public DepthStencil(DisposableI parent, int width, int height, DepthStencilFormats depthStencilFormats) : base(parent) { try { video = parent.FindParentOrSelfWithException <Video>(); PixelFormat format = PixelFormat.None; switch (depthStencilFormats) { case DepthStencilFormats.Defualt: format = PixelFormat.Depth16; break; case DepthStencilFormats.Depth24Stencil8: format = PixelFormat.Depth24Stencil8; break; case DepthStencilFormats.Depth16: format = PixelFormat.Depth16; break; case DepthStencilFormats.Depth24: format = PixelFormat.Depth24; break; default: Debug.ThrowError("Video", "Unsuported DepthStencilFormat type"); break; } depthBuffer = new DepthBuffer(width, height, format); } catch (Exception e) { Dispose(); throw e; } }
private void initDepthStencil(int width, int height, DepthStencilFormats depthStencilFormat) { if (depthStencilFormat != DepthStencilFormats.None) { depthStencil = new DepthStencil(this, width, height, depthStencilFormat); } }
public static IRenderTarget New(VideoTypes videoType, IDisposableResource parent, string filename, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, DepthStencilFormats depthStencilFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, Loader.LoadedCallbackMethod loadedCallback) { IRenderTarget api = null; #if WIN32 if (videoType == VideoTypes.D3D9) api = new D3D9.RenderTarget(parent, filename, width, height, generateMipmaps, multiSampleType, surfaceFormat, depthStencilFormat, renderTargetUsage, usage, loadedCallback); #endif #if WIN32 || WINRT || WP8 if (videoType == VideoTypes.D3D11) api = new D3D11.RenderTarget(parent, filename, width, height, generateMipmaps, multiSampleType, surfaceFormat, depthStencilFormat, renderTargetUsage, usage, loadedCallback); #endif #if WIN32 || OSX || LINUX || iOS || ANDROID || NaCl if (videoType == VideoTypes.OpenGL) api = new OpenGL.RenderTarget(parent, filename, width, height, generateMipmaps, multiSampleType, surfaceFormat, depthStencilFormat, renderTargetUsage, usage, loadedCallback); #endif #if XNA if (videoType == VideoTypes.XNA) api = new XNA.RenderTarget(parent, filename, width, height, generateMipmaps, multiSampleType, surfaceFormat, depthStencilFormat, renderTargetUsage, usage, loadedCallback); #endif #if VITA if (videoType == VideoTypes.Vita) api = new Vita.RenderTarget(parent, filename, width, height, generateMipmaps, multiSampleType, surfaceFormat, depthStencilFormat, renderTargetUsage, usage, loadedCallback); #endif if (api == null) Debug.ThrowError("RenderTargetAPI", "Unsuported InputType: " + videoType); return api; }
public DepthStencil(DisposableI parent, int width, int height, DepthStencilFormats depthStencilFormats) : base(parent) { try { video = parent.FindParentOrSelfWithException<Video>(); PixelFormat format = PixelFormat.None; switch (depthStencilFormats) { case DepthStencilFormats.Defualt: format = PixelFormat.Depth16; break; case DepthStencilFormats.Depth24Stencil8: format = PixelFormat.Depth24Stencil8; break; case DepthStencilFormats.Depth16: format = PixelFormat.Depth16; break; case DepthStencilFormats.Depth24: format = PixelFormat.Depth24; break; default: Debug.ThrowError("Video", "Unsuported DepthStencilFormat type"); break; } depthBuffer = new DepthBuffer(width, height, format); } catch (Exception e) { Dispose(); throw e; } }
public DepthStencil(IDisposableResource parent, int width, int height, DepthStencilFormats depthStencilFormats) : base(parent) { try { var video = parent.FindParentOrSelfWithException <Video>(); Size = new Size2(width, height); SizeF = Size.ToVector2(); int depthBit = 16, stencilBit = 0; switch (depthStencilFormats) { 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 DepthStencilCom(); var error = com.Init(video.com, width, height, depthBit, stencilBit); switch (error) { case DepthStencilErrors.Textrue: Debug.ThrowError("DepthStencil", "Failed to create Texture2D"); break; case DepthStencilErrors.DepthStencilView: Debug.ThrowError("DepthStencil", "Failed to create DepthStencilView"); break; } } catch (Exception e) { Dispose(); throw e; } }
public DepthStencil(IDisposableResource parent, int width, int height, DepthStencilFormats depthStencilFormats) : base(parent) { try { var video = parent.FindParentOrSelfWithException<Video>(); Size = new Size2(width, height); SizeF = Size.ToVector2(); int depthBit = 16, stencilBit = 0; switch (depthStencilFormats) { 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 DepthStencilCom(); var error = com.Init(video.com, width, height, depthBit, stencilBit); switch (error) { case DepthStencilErrors.Textrue: Debug.ThrowError("DepthStencil", "Failed to create Texture2D"); break; case DepthStencilErrors.DepthStencilView: Debug.ThrowError("DepthStencil", "Failed to create DepthStencilView"); break; } } catch (Exception e) { Dispose(); throw e; } }
public Video(IDisposableResource parent, IApplication application, DepthStencilFormats depthStencilFormats, bool vSync) : base(parent) { #if WINRT var xamlApp = application as XAMLApplication; init(parent, application, depthStencilFormats, vSync, xamlApp != null ? ((XAMLApplication)application).SwapChainPanel : null); #else init(parent, application, depthStencilFormats, vSync); #endif }
public Video(IDisposableResource parent, IApplication application, DepthStencilFormats depthStencilFormats, bool vSync) : base(parent) { #if WINRT var xamlApp = application as XAMLApplication; init(parent, application, depthStencilFormats, vSync, xamlApp != null ? ((XAMLApplication)application).SwapChainPanel : null); #else init(parent, application, depthStencilFormats, vSync); #endif }
public Video(DisposableI parent, ApplicationI application, DepthStencilFormats depthStencilFormats, bool vSync) : base(parent) { try { this.application = application; FileTag = "Vita_"; currentPixelTextures = new Texture2D[4]; currentSamplerStates = new SamplerState[4]; PixelFormat format = PixelFormat.None; switch (depthStencilFormats) { case DepthStencilFormats.None: format = PixelFormat.None; break; case DepthStencilFormats.Defualt: format = PixelFormat.Depth16; break; case DepthStencilFormats.Depth24Stencil8: format = PixelFormat.Depth24Stencil8; break; case DepthStencilFormats.Depth16: format = PixelFormat.Depth16; break; case DepthStencilFormats.Depth24: format = PixelFormat.Depth24; break; default: Debug.ThrowError("Video", "Unsuported DepthStencilFormat type"); break; } context = new GraphicsContext(0, 0, PixelFormat.Rgba, format, MultiSampleMode.None); currentFrameBuffer = context.Screen; BackBufferSize = new Size2(currentFrameBuffer.Width, currentFrameBuffer.Height); ((VitaApplication)application).Vita_SetFrameSize(currentFrameBuffer.Width, currentFrameBuffer.Height); currentEnableMode = EnableMode.None; context.Enable(currentEnableMode); } catch (Exception e) { Dispose(); throw e; } }
public Video(DisposableI parent, ApplicationI application, DepthStencilFormats depthStencilFormats, bool vSync) : base(parent) { if (depthStencilFormats != DepthStencilFormats.Defualt) { Debug.ThrowError("Video", "Only a Defualt DepthStenicFormat may be used in XNA here"); } this.application = application; Device = application.GraphicsDevice; defualtStates(); #if SILVERLIGHT FileTag = "Silverlight_"; #else FileTag = "XNA_"; #endif BackBufferSize = application.FrameSize; backBuffers = Device.GetRenderTargets(); }
public Video(DisposableI parent, ApplicationI application, DepthStencilFormats depthStencilFormats, bool vSync) : base(parent) { try { this.application = application; FileTag = "Vita_"; currentPixelTextures = new Texture2D[4]; currentSamplerStates = new SamplerState[4]; PixelFormat format = PixelFormat.None; switch (depthStencilFormats) { case DepthStencilFormats.None: format = PixelFormat.None; break; case DepthStencilFormats.Defualt: format = PixelFormat.Depth16; break; case DepthStencilFormats.Depth24Stencil8: format = PixelFormat.Depth24Stencil8; break; case DepthStencilFormats.Depth16: format = PixelFormat.Depth16; break; case DepthStencilFormats.Depth24: format = PixelFormat.Depth24; break; default: Debug.ThrowError("Video", "Unsuported DepthStencilFormat type"); break; } context = new GraphicsContext(0, 0, PixelFormat.Rgba, format, MultiSampleMode.None); currentFrameBuffer = context.Screen; BackBufferSize = new Size2(currentFrameBuffer.Width, currentFrameBuffer.Height); ((VitaApplication)application).Vita_SetFrameSize(currentFrameBuffer.Width, currentFrameBuffer.Height); currentEnableMode = EnableMode.None; context.Enable(currentEnableMode); } catch (Exception e) { Dispose(); throw e; } }
public static IDepthStencil New(VideoTypes videoType, IDisposableResource parent, int width, int height, DepthStencilFormats format) { IDepthStencil api = null; #if WIN32 if (videoType == VideoTypes.D3D9) api = new D3D9.DepthStencil(parent, width, height, format); #endif #if WIN32 || WINRT || WP8 if (videoType == VideoTypes.D3D11) api = new D3D11.DepthStencil(parent, width, height, format); #endif #if WIN32 || OSX || LINUX || iOS || ANDROID || NaCl if (videoType == VideoTypes.OpenGL) api = new OpenGL.DepthStencil(parent, width, height, format); #endif #if VITA if (videoType == VideoTypes.Vita) api = new Vita.DepthStencil(parent, width, height, format); #endif if (api == null) Debug.ThrowError("DepthStencilAPI", "Unsuported InputType: " + videoType); return api; }
public static RenderTarget New(DisposableI parent, int width, int height, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, DepthStencilFormats depthStencilFormat, BufferUsages usage, RenderTargetUsage renderTargetUsage, Loader.LoadedCallbackMethod loadedCallback) { return new RenderTarget(parent, width, height, multiSampleType, surfaceFormat, depthStencilFormat, usage, renderTargetUsage, loadedCallback); }
public static IVideo New(VideoTypes videoTypeFlags, out VideoTypes videoType, IDisposableResource parent, IApplication application, DepthStencilFormats depthStencilFormats, bool vSync) { bool d3d11 = (videoTypeFlags & VideoTypes.D3D11) != 0; bool d3d9 = (videoTypeFlags & VideoTypes.D3D9) != 0; bool gl = (videoTypeFlags & VideoTypes.OpenGL) != 0; bool xna = (videoTypeFlags & VideoTypes.XNA) != 0; bool vita = (videoTypeFlags & VideoTypes.Vita) != 0; videoType = VideoTypes.None; Exception lastException = null; IVideo video = null; while (true) { try { #if WIN32 || WINRT || WP8 if (d3d11) { d3d11 = false; videoType = VideoTypes.D3D11; video = new Reign.Video.D3D11.Video(parent, application, depthStencilFormats, vSync); break; } #endif #if WIN32 else if (d3d9) { d3d9 = false; videoType = VideoTypes.D3D9; video = new Reign.Video.D3D9.Video(parent, application, depthStencilFormats, vSync); break; } #endif #if WIN32 || OSX || LINUX || NaCl || iOS || ANDROID if (gl) { gl = false; videoType = VideoTypes.OpenGL; video = new Reign.Video.OpenGL.Video(parent, application, depthStencilFormats, vSync); break; } #endif #if XNA if (xna) { xna = false; videoType = VideoTypes.XNA; video = new Reign.Video.XNA.Video(parent, application, depthStencilFormats, vSync); break; } #endif #if VITA if (vita) { vita = false; videoType = VideoTypes.Vita; video = new Reign.Video.Vita.Video(parent, application, depthStencilFormats, vSync); break; } #endif else { break; } } catch (Exception e) { lastException = e; } } // check for error if (lastException != null) { string ex = lastException == null ? "" : " - Exception: " + lastException.Message; Debug.ThrowError("VideoAPI", "Failed to create Video API" + ex); videoType = VideoTypes.None; } if (videoType != VideoTypes.None) { DefaultAPI = videoType; } return(video); }
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; } }
private void init(IDisposableResource parent, IApplication application, DepthStencilFormats depthStencilFormats, bool vSync, Windows.UI.Xaml.Controls.SwapChainBackgroundPanel swapChainBackgroundPanel)
public Video(IDisposableResource parent, IApplication application, DepthStencilFormats depthStencilFormats, bool vSync) : base(parent) { try { int depthBit = 16, stencilBit = 0; switch (depthStencilFormats) { case DepthStencilFormats.None: depthBit = 0; stencilBit = 0; break; case DepthStencilFormats.Defualt: #if iOS || ANDROID || NaCl || RPI depthBit = 16; stencilBit = 0; #else depthBit = 24; stencilBit = 0; #endif 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; } currentTextures = new Texture2D[8]; currentSamplerStates = new SamplerState[8]; #if WIN32 || OSX || LINUX || NaCl BackBufferSize = application.FrameSize; this.application = application; #else BackBufferSize = application.FrameSize; this.application = application; #endif #if WIN32 //Get DC handle = application.Handle; dc = WGL.GetDC(handle); WGL.SwapBuffers(dc); //Set BackBuffer format WGL.PIXELFORMATDESCRIPTOR pfd = new WGL.PIXELFORMATDESCRIPTOR(); WGL.ZeroPixelDescriptor(ref pfd); pfd.nVersion = 1; pfd.dwFlags = WGL.PFD_DRAW_TO_WINDOW | WGL.PFD_SUPPORT_OPENGL | WGL.PFD_DOUBLEBUFFER; pfd.iPixelType = (byte)WGL.PFD_TYPE_RGBA; //pfd.cColorBits = 24; //pfd.cAlphaBits = 8; pfd.cDepthBits = (byte)depthBit; pfd.cStencilBits = (byte)stencilBit; pfd.iLayerType = (byte)WGL.PFD_MAIN_PLANE; unsafe { pfd.nSize = (ushort)sizeof(WGL.PIXELFORMATDESCRIPTOR); } int pixelFormatIndex = WGL.ChoosePixelFormat(dc, ref pfd); if (pixelFormatIndex == 0) { Debug.ThrowError("Video", "ChoosePixelFormat failed"); } if (WGL.SetPixelFormat(dc, pixelFormatIndex, ref pfd) == 0) { Debug.ThrowError("Video", "Failed to set PixelFormat"); } ctx = WGL.CreateContext(dc); if (ctx == IntPtr.Zero) { Debug.ThrowError("Video", "Failed to create GL context"); } if (WGL.MakeCurrent(dc, ctx) == 0) { Debug.ThrowError("Video", "Failed to make GL context current"); } WGL.Init(); WGL.SwapInterval(vSync ? 1 : 0); // -1 for smart vsync #endif #if RPI unsafe { // Init Pi video RaspberryPi.bcm_host_init(); const int piDisplay = 0; uint piWidth = 0, piHeight = 0; if (RaspberryPi.graphics_get_display_size(piDisplay, &piWidth, &piHeight) < 0) { Debug.ThrowError("Video", "Failed to get display size"); } Console.WriteLine("piWidth - " + piWidth); Console.WriteLine("piHeight - " + piHeight); BackBufferSize = new Size2((int)piWidth, (int)piHeight); IntPtr dispman_display = RaspberryPi.vc_dispmanx_display_open(piDisplay); if (dispman_display == IntPtr.Zero) { Debug.ThrowError("Video", "Failed: vc_dispmanx_display_open"); } IntPtr dispman_update = RaspberryPi.vc_dispmanx_update_start(0); if (dispman_update == IntPtr.Zero) { Debug.ThrowError("Video", "Failed: vc_dispmanx_update_start"); } var dstRect = new RaspberryPi.VC_RECT_T() { x = 0, y = 0, width = (int)piWidth, height = (int)piHeight }; var srcRect = new RaspberryPi.VC_RECT_T() { x = 0, y = 0, width = ((int)piWidth) << 16, height = ((int)piHeight) << 16 }; IntPtr dispman_element = RaspberryPi.vc_dispmanx_element_add(dispman_update, dispman_display, 0, &dstRect, IntPtr.Zero, &srcRect, RaspberryPi.DISPMANX_PROTECTION_NONE, IntPtr.Zero, IntPtr.Zero, 0); if (dispman_element == IntPtr.Zero) { Debug.ThrowError("Video", "Failed: vc_dispmanx_element_add"); } nativeWindow = new RaspberryPi.DISPMANX_WINDOW_T() { element = dispman_element, width = (int)piWidth, height = (int)piHeight }; windowHandle = GCHandle.Alloc(nativeWindow, GCHandleType.Pinned); RaspberryPi.vc_dispmanx_update_submit_sync(dispman_update); // Init EGL handle = application.Handle; GL.GetError(); //NOTE: THIS MUST BE HERE SO THAT libGLES LOADS BEFORE libEGL dc = EGL.GetDisplay(IntPtr.Zero); int major, minor; if (!EGL.Initialize(dc, out major, out minor)) { Debug.ThrowError("Video", string.Format("Failed to initialize display connection, Error {0}", EGL.GetError())); } int[] pixelFormat = new int[] { //EGL.RENDERABLE_TYPE, EGL.OPENGL_ES2_BIT, //EGL.RED_SIZE, 5, //EGL.GREEN_SIZE, 6, //EGL.BLUE_SIZE, 5, //EGL.ALPHA_SIZE, 0,//EGL.DONT_CARE, EGL.SURFACE_TYPE, EGL.WINDOW_BIT, EGL.DEPTH_SIZE, depthBit, //EGL.STENCIL_SIZE, stencilBit,//EGL.DONT_CARE,//<<<<<<<<<< Test enabling this! //EGL.SAMPLE_BUFFERS, 0, //EGL.SAMPLES, 0, //EGL.MIN_SWAP_INTERVAL, 0, //EGL.MAX_SWAP_INTERVAL, 1, EGL.NONE, }; int num_configs; var configs = new IntPtr(); if (EGL.ChooseConfig(dc, pixelFormat, &configs, 1, &num_configs) == 0 || num_configs == 0) { Debug.ThrowError("Video", string.Format("Failed to retrieve GraphicsMode, error {0}", EGL.GetError())); } if (EGL.BindAPI(EGL.OPENGL_ES_API) == 0) { Debug.ThrowError("Video", "Failed to bind GLES API"); } ; int[] attrib_list = new int[] { EGL.CONTEXT_CLIENT_VERSION, 2, EGL.NONE }; ctx = EGL.CreateContext(dc, configs, IntPtr.Zero, attrib_list); if (ctx == IntPtr.Zero) { Debug.ThrowError("Video", "Failed to create context"); } surface = EGL.CreateWindowSurface(dc, configs, windowHandle.AddrOfPinnedObject(), null); //surface = EGL.CreateWindowSurface(dc, configs[0], handle, null);// <<<<<<<<<<<<<<<<<<<<<<<<<<<< used in x11 if (surface == IntPtr.Zero) { Debug.ThrowError("Video", "Failed to create window surface"); } if (EGL.MakeCurrent(dc, surface, surface, ctx) == 0) { Debug.ThrowError("Video", "Failed to make EGL context current"); } //if (EGL.SwapInterval(dc, vSync ? 1 : 0) == 0) Debug.ThrowError("Video", "Failed to set vSync"); checkForEGLError(); } #elif LINUX //Get DC handle = application.Handle; dc = X11.XOpenDisplay(IntPtr.Zero); int screen = X11.XDefaultScreen(dc); //Set Pixel format int[] attrbs = { GLX.RGBA, GLX.DOUBLEBUFFER,// 1, //GLX.RED_SIZE, 8, //GLX.GREEN_SIZE, 8, //GLX.BLUE_SIZE, 8, //GLX.ALPHA_SIZE, 8, GLX.DEPTH_SIZE,depthBit, GLX.NONE }; IntPtr visual = GLX.ChooseVisual(dc, screen, attrbs); if (visual == IntPtr.Zero) { Debug.ThrowError("Video", "Failed to get visual"); } ctx = GLX.CreateContext(dc, visual, new IntPtr(0), true); GLX.MakeCurrent(dc, handle, ctx); bool failed = false; try { GLX.SwapIntervalSGI(vSync ? 1 : 0); } catch { failed = true; } if (failed) { GLX.Init(); GLX.SwapIntervalMesa(vSync ? 1 : 0); } #endif #if OSX var attribs = new object[] { NSOpenGLPixelFormatAttribute.Window, NSOpenGLPixelFormatAttribute.Accelerated, NSOpenGLPixelFormatAttribute.NoRecovery, NSOpenGLPixelFormatAttribute.DoubleBuffer, NSOpenGLPixelFormatAttribute.ColorSize, 24, NSOpenGLPixelFormatAttribute.AlphaSize, 8, NSOpenGLPixelFormatAttribute.DepthSize, depthBit }; var pixelFormat = new NSOpenGLPixelFormat(attribs); if (pixelFormat == null) { Debug.ThrowError("Video", "NSOpenGLPixelFormat failed"); } NSContext = new NSOpenGLContext(pixelFormat, null); if (NSContext == null) { Debug.ThrowError("Video", "Failed to create GL context"); } NSContext.MakeCurrentContext(); NSContext.SwapInterval = vSync; NSContext.View = application.View; ctx = NSContext.CGLContext.Handle; OS.NSContext = NSContext; /*//Get DC * dc = CGL.DisplayIDToOpenGLDisplayMask(CGL.MainDisplayID()); * if (dc == IntPtr.Zero) Debug.ThrowError("Video", "Failed to get DC"); * * //Set BackBuffer format * int[] attributes = * { * //(int)CGL.PixelFormatAttribute.kCGLPFADoubleBuffer, * //(int)CGL.PixelFormatAttribute.kCGLPFADisplayMask, dc.ToInt32(), * //(int)CGL.PixelFormatAttribute.kCGLPFAWindow, * (int)CGL.PixelFormatAttribute.kCGLPFAAccelerated, * (int)CGL.PixelFormatAttribute.kCGLPFAColorSize, 32, * (int)CGL.PixelFormatAttribute.kCGLPFADepthSize, depthBit, * 0 * }; * * IntPtr pixelFormat = IntPtr.Zero; * int pixelFormatCount = 0; * int error = CGL.ChoosePixelFormat(attributes, ref pixelFormat, ref pixelFormatCount); * if (error != 0 || pixelFormat == IntPtr.Zero) * { * Debug.ThrowError("Video", "ChoosePixelFormat failed"); * } * * error = CGL.CreateContext(pixelFormat, IntPtr.Zero, ref ctx); * if (error != 0 || ctx == IntPtr.Zero) * { * Debug.ThrowError("Video", "Failed to create GL fullscreen context"); * } * * CGL.SetCurrentContext(ctx);*/ #endif #if iOS // GL will be created by the Application #endif #if ANDROID // GL will be created by the Application #endif #if NaCl var frame = application.FrameSize; int[] attribs = { (int)PPAPI.Graphics3DAttrib.PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8,// Try to disable this to see if it gets rid of alpha blending presintation issues (int)PPAPI.Graphics3DAttrib.PP_GRAPHICS3DATTRIB_DEPTH_SIZE, depthBit, (int)PPAPI.Graphics3DAttrib.PP_GRAPHICS3DATTRIB_STENCIL_SIZE, stencilBit, (int)PPAPI.Graphics3DAttrib.PP_GRAPHICS3DATTRIB_SAMPLES, 0, (int)PPAPI.Graphics3DAttrib.PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, 0, (int)PPAPI.Graphics3DAttrib.PP_GRAPHICS3DATTRIB_WIDTH, frame.Width, (int)PPAPI.Graphics3DAttrib.PP_GRAPHICS3DATTRIB_HEIGHT, frame.Height, (int)PPAPI.Graphics3DAttrib.PP_GRAPHICS3DATTRIB_NONE }; graphics = OS.GetGraphics(); if (graphics == IntPtr.Zero) { Debug.ThrowError("Video", "Failed to get Graphics object"); } IntPtr pbbInstance = OS.GetPBBInstance(); if (graphics == IntPtr.Zero) { Debug.ThrowError("Video", "Failed to get PBBInstance object"); } IntPtr gles = OS.GetGlES(); if (gles == IntPtr.Zero) { Debug.ThrowError("Video", "Failed to get GLES object"); } context = PPAPI.InitOpenGL(OS.GetInstance(), graphics, pbbInstance, attribs, gles); if (context == 0) { Debug.ThrowError("Video", "Failed to create GL context"); } PPAPI.SetCurrentContextPPAPI(context); PPAPI.StartSwapBufferLoop(graphics, context); #endif checkForError(); //Setup defualt OpenGL characteristics GL.FrontFace(GL.CCW); // Get Caps Caps = new Caps(); Caps.MaxShaderVersion = ShaderVersions.Unknown; unsafe { int max = 0; GL.GetIntegerv(GL.MAX_TEXTURE_SIZE, &max); Caps.MaxTextureSize = max; // SEEMS TO MESS UP ON OSX //GL.GetIntegerv(GL.MAX_VERTEX_UNIFORM_VECTORS, &max); //Caps.MaxVertexConstants = max; //GL.GetIntegerv(GL.MAX_FRAGMENT_UNIFORM_VECTORS, &max); //Caps.MaxPixelConstants = max; #if RPI byte *shaderVersionPtr = null; #else byte *shaderVersionPtr = GL.GetString(GL.SHADING_LANGUAGE_VERSION); #endif string shaderVersion = ""; while (shaderVersionPtr != null && shaderVersionPtr[0] != 0) { shaderVersion += (char)shaderVersionPtr[0]; shaderVersionPtr++; } #if iOS || RPI shaderVersion = "1.0"; #elif ANDROID shaderVersion = shaderVersion.Substring(shaderVersion.Length - 4, 4); #elif NaCl shaderVersion = shaderVersion.Substring(18, 3); #else shaderVersion = shaderVersion.Substring(0, 4); #endif float shaderValue = Convert.ToSingle(shaderVersion); Caps.Version = Versions.GL1; FileTag = ""; #if iOS || ANDROID || NaCl || RPI if (shaderValue >= 1.0f) { Caps.Version = Versions.GL2; FileTag = "GLES2_"; Caps.MaxShaderVersion = ShaderVersions.GLSL_1_00; } #else if (shaderValue >= 1.1f) { Caps.Version = Versions.GL2; FileTag = "GL2_"; Caps.MaxShaderVersion = ShaderVersions.GLSL_1_10; } if (shaderValue >= 1.2f) { Caps.Version = Versions.GL2; FileTag = "GL2_"; Caps.MaxShaderVersion = ShaderVersions.GLSL_1_20; } // GL3 not supported in GLSL 1.30 becuase 'gl_InstanceID' only exists in GLSL 1.40 /*if (shaderValue >= 1.3f) * { * Caps.Version = Versions.GL3; * IShader.FileTag = "GL3_"; * Caps.MaxShaderVersion = ShaderVersions.GLSL_1_30; * }*/ if (shaderValue >= 1.4f) { Caps.Version = Versions.GL3; FileTag = "GL3_"; Caps.MaxShaderVersion = ShaderVersions.GLSL_1_40; } if (shaderValue >= 1.5f) { Caps.Version = Versions.GL3; FileTag = "GL3_"; Caps.MaxShaderVersion = ShaderVersions.GLSL_1_50; } if (shaderValue >= 3.3f) { Caps.Version = Versions.GL3; FileTag = "GL3_"; Caps.MaxShaderVersion = ShaderVersions.GLSL_3_30; } //if (shaderValue >= 4.0f) Caps.MaxShaderVersion = ShaderVersions.GLSL_4_00; //if (shaderValue >= 4.1f) Caps.MaxShaderVersion = ShaderVersions.GLSL_4_10; //if (shaderValue >= 4.2f) Caps.MaxShaderVersion = ShaderVersions.GLSL_4_20; #endif if (Caps.Version == Versions.GL1) { Debug.ThrowError("Video", "OpenGL 2 or higher is required.\nAre your video card drivers up to date?"); } byte * extensionsPtr = GL.GetString(GL.EXTENSIONS); string extensionValues = ""; while (extensionsPtr != null && extensionsPtr[0] != 0) { extensionValues += (char)extensionsPtr[0]; extensionsPtr++; } var extensions = extensionValues.Split(' '); foreach (var ext in extensions) { switch (ext) { case "GL_instanced_arrays": Caps.HardwareInstancing = true; break; case "GL_ARB_instanced_arrays": Caps.HardwareInstancing = true; break; case "GL_EXT_texture_compression_s3tc": Caps.TextureCompression_S3TC = true; break; case "GL_AMD_compressed_ATC_texture": Caps.TextureCompression_ATC = true; break; case "GL_ATI_texture_compression_atitc": Caps.TextureCompression_ATC = true; break; case "GL_IMG_texture_compression_pvrtc": Caps.TextureCompression_PVR = true; break; } //Console.WriteLine(ext); } } checkForError(); // Init Ext GL.Init(); } catch (Exception e) { Dispose(); throw e; } }
public unsafe DepthStencil(IDisposableResource parent, int width, int height, DepthStencilFormats depthStencilFormats) : base(parent) { try { uint depthBit = GL.DEPTH_COMPONENT16, stencilBit = 0; switch (depthStencilFormats) { case DepthStencilFormats.Defualt: #if iOS || ANDROID || NaCl || RPI depthBit = GL.DEPTH_COMPONENT16; stencilBit = 0; #else depthBit = GL.DEPTH_COMPONENT24; stencilBit = 0; #endif break; case DepthStencilFormats.Depth24Stencil8: depthBit = GL.DEPTH_COMPONENT24; stencilBit = GL.STENCIL_INDEX8; break; case DepthStencilFormats.Depth16: depthBit = GL.DEPTH_COMPONENT16; stencilBit = 0; break; case DepthStencilFormats.Depth24: depthBit = GL.DEPTH_COMPONENT24; stencilBit = 0; break; case DepthStencilFormats.Depth32: depthBit = GL.DEPTH_COMPONENT32; stencilBit = 0; break; default: Debug.ThrowError("DepthStencil", "Unsuported DepthStencilFormat type"); break; } Size = new Size2(width, height); SizeF = Size.ToVector2(); // create depth uint surfaceTEMP = 0; GL.GenRenderbuffers(1, &surfaceTEMP); if (surfaceTEMP == 0) { Debug.ThrowError("DpethStencil", "Failed to create DepthBuffer"); } depthBuffer = surfaceTEMP; GL.BindRenderbuffer(GL.RENDERBUFFER, depthBuffer); GL.RenderbufferStorage(GL.RENDERBUFFER, depthBit, width, height); // create stencil if (stencilBit != 0) { surfaceTEMP = 0; GL.GenRenderbuffers(1, &surfaceTEMP); if (surfaceTEMP == 0) { Debug.ThrowError("DpethStencil", "Failed to create StencilBuffer"); } stencilBuffer = surfaceTEMP; GL.BindRenderbuffer(GL.RENDERBUFFER, stencilBuffer); GL.RenderbufferStorage(GL.RENDERBUFFER, stencilBit, width, height); } uint error; string errorName; if (Video.checkForError(out error, out errorName)) { Debug.ThrowError("DepthStencil", string.Format("{0} {1}: Failed to create DepthStencil", error, errorName)); } } catch (Exception e) { Dispose(); throw e; } }
public unsafe DepthStencil(IDisposableResource parent, int width, int height, DepthStencilFormats depthStencilFormats) : base(parent) { try { uint depthBit = GL.DEPTH_COMPONENT16, stencilBit = 0; switch (depthStencilFormats) { case DepthStencilFormats.Defualt: #if iOS || ANDROID || NaCl || RPI depthBit = GL.DEPTH_COMPONENT16; stencilBit = 0; #else depthBit = GL.DEPTH_COMPONENT24; stencilBit = 0; #endif break; case DepthStencilFormats.Depth24Stencil8: depthBit = GL.DEPTH_COMPONENT24; stencilBit = GL.STENCIL_INDEX8; break; case DepthStencilFormats.Depth16: depthBit = GL.DEPTH_COMPONENT16; stencilBit = 0; break; case DepthStencilFormats.Depth24: depthBit = GL.DEPTH_COMPONENT24; stencilBit = 0; break; case DepthStencilFormats.Depth32: depthBit = GL.DEPTH_COMPONENT32; stencilBit = 0; break; default: Debug.ThrowError("DepthStencil", "Unsuported DepthStencilFormat type"); break; } Size = new Size2(width, height); SizeF = Size.ToVector2(); // create depth uint surfaceTEMP = 0; GL.GenRenderbuffers(1, &surfaceTEMP); if (surfaceTEMP == 0) Debug.ThrowError("DpethStencil", "Failed to create DepthBuffer"); depthBuffer = surfaceTEMP; GL.BindRenderbuffer(GL.RENDERBUFFER, depthBuffer); GL.RenderbufferStorage(GL.RENDERBUFFER, depthBit, width, height); // create stencil if (stencilBit != 0) { surfaceTEMP = 0; GL.GenRenderbuffers(1, &surfaceTEMP); if (surfaceTEMP == 0) Debug.ThrowError("DpethStencil", "Failed to create StencilBuffer"); stencilBuffer = surfaceTEMP; GL.BindRenderbuffer(GL.RENDERBUFFER, stencilBuffer); GL.RenderbufferStorage(GL.RENDERBUFFER, stencilBit, width, height); } uint error; string errorName; if (Video.checkForError(out error, out errorName)) Debug.ThrowError("DepthStencil", string.Format("{0} {1}: Failed to create DepthStencil", error, errorName)); } catch (Exception e) { Dispose(); throw e; } }
private void init(IDisposableResource parent, int width, int height, DepthStencilFormats depthStencilFormats) { try { this.width = width; this.height = height; this.depthStencilFormats = depthStencilFormats; video = parent.FindParentOrSelfWithException <Video>(); Size = new Size2(width, height); SizeF = Size.ToVector2(); int depthBit = 16, stencilBit = 0; switch (depthStencilFormats) { 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 DepthStencilCom(); var error = com.Init(video.com, width, height, depthBit, stencilBit); switch (error) { case DepthStencilErrors.DepthStencilSurface: Debug.ThrowError("DepthStencil", "Failed to create DepthStencil Surface"); break; } if (!video.Caps.ExDevice && !video.deviceReseting) { video.DeviceLost += deviceLost; video.DeviceReset += deviceReset; } } catch (Exception e) { Dispose(); throw e; } }
public static IDepthStencil New(VideoTypes videoType, IDisposableResource parent, int width, int height, DepthStencilFormats format) { IDepthStencil api = null; #if WIN32 if (videoType == VideoTypes.D3D9) { api = new D3D9.DepthStencil(parent, width, height, format); } #endif #if WIN32 || WINRT || WP8 if (videoType == VideoTypes.D3D11) { api = new D3D11.DepthStencil(parent, width, height, format); } #endif #if WIN32 || OSX || LINUX || iOS || ANDROID || NaCl if (videoType == VideoTypes.OpenGL) { api = new OpenGL.DepthStencil(parent, width, height, format); } #endif #if VITA if (videoType == VideoTypes.Vita) { api = new Vita.DepthStencil(parent, width, height, format); } #endif if (api == null) { Debug.ThrowError("DepthStencilAPI", "Unsuported InputType: " + videoType); } return(api); }
public static IDepthStencil New(IDisposableResource parent, int width, int height, DepthStencilFormats format) { return(New(VideoAPI.DefaultAPI, parent, width, height, format)); }
public static RenderTarget New(DisposableI parent, int width, int height, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, DepthStencilFormats depthStencilFormat, BufferUsages usage, RenderTargetUsage renderTargetUsage, Loader.LoadedCallbackMethod loadedCallback) { return(new RenderTarget(parent, width, height, multiSampleType, surfaceFormat, depthStencilFormat, usage, renderTargetUsage, loadedCallback)); }
private void init(IDisposableResource parent, int width, int height, DepthStencilFormats depthStencilFormats) { try { this.width = width; this.height = height; this.depthStencilFormats = depthStencilFormats; video = parent.FindParentOrSelfWithException<Video>(); Size = new Size2(width, height); SizeF = Size.ToVector2(); int depthBit = 16, stencilBit = 0; switch (depthStencilFormats) { 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 DepthStencilCom(); var error = com.Init(video.com, width, height, depthBit, stencilBit); switch (error) { case DepthStencilErrors.DepthStencilSurface: Debug.ThrowError("DepthStencil", "Failed to create DepthStencil Surface"); break; } if (!video.Caps.ExDevice && !video.deviceReseting) { video.DeviceLost += deviceLost; video.DeviceReset += deviceReset; } } catch (Exception e) { Dispose(); throw e; } }
public DepthStencil(IDisposableResource parent, int width, int height, DepthStencilFormats depthStencilFormats) : base(parent) { init(parent, width, height, depthStencilFormats); }
public RenderTarget(IDisposableResource parent, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, DepthStencilFormats depthStencilFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, Loader.LoadedCallbackMethod loadedCallback) : base(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, loadedCallback) { if (initSuccess) initDepthStencil(width, height, depthStencilFormat); }
public static IDepthStencil New(IDisposableResource parent, int width, int height, DepthStencilFormats format) { return New(VideoAPI.DefaultAPI, parent, width, height, format); }
public DepthStencil(IDisposableResource parent, int width, int height, DepthStencilFormats depthStencilFormats) : base(parent) { init(parent, width, height, depthStencilFormats); }
public static DepthStencilI New(DisposableI parent, int width, int height, DepthStencilFormats depthStencilFormats) { return(new DepthStencil(parent, width, height, depthStencilFormats)); }
private void initDepthStencil(int width, int height, DepthStencilFormats depthStencilFormat) { if (depthStencilFormat != DepthStencilFormats.None) depthStencil = new DepthStencil(this, width, height, depthStencilFormat); }
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; } }
public static DepthStencilI New(DisposableI parent, int width, int height, DepthStencilFormats depthStencilFormats) { return new DepthStencil(parent, width, height, depthStencilFormats); }
public static IRenderTarget New(IDisposableResource parent, int width, int height, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, DepthStencilFormats depthStencilFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, Loader.LoadedCallbackMethod loadedCallback) { return New(VideoAPI.DefaultAPI, parent, (Image)null, width, height, false, multiSampleType, surfaceFormat, depthStencilFormat, renderTargetUsage, usage, loadedCallback); }
private void init(IDisposableResource parent, IApplication application, DepthStencilFormats depthStencilFormats, bool vSync, Windows.UI.Xaml.Controls.SwapChainBackgroundPanel swapChainBackgroundPanel)
public static IRenderTarget New(VideoTypes videoType, IDisposableResource parent, string filename, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, DepthStencilFormats depthStencilFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, Loader.LoadedCallbackMethod loadedCallback) { IRenderTarget api = null; #if WIN32 if (videoType == VideoTypes.D3D9) { api = new D3D9.RenderTarget(parent, filename, width, height, generateMipmaps, multiSampleType, surfaceFormat, depthStencilFormat, renderTargetUsage, usage, loadedCallback); } #endif #if WIN32 || WINRT || WP8 if (videoType == VideoTypes.D3D11) { api = new D3D11.RenderTarget(parent, filename, width, height, generateMipmaps, multiSampleType, surfaceFormat, depthStencilFormat, renderTargetUsage, usage, loadedCallback); } #endif #if WIN32 || OSX || LINUX || iOS || ANDROID || NaCl if (videoType == VideoTypes.OpenGL) { api = new OpenGL.RenderTarget(parent, filename, width, height, generateMipmaps, multiSampleType, surfaceFormat, depthStencilFormat, renderTargetUsage, usage, loadedCallback); } #endif #if XNA if (videoType == VideoTypes.XNA) { api = new XNA.RenderTarget(parent, filename, width, height, generateMipmaps, multiSampleType, surfaceFormat, depthStencilFormat, renderTargetUsage, usage, loadedCallback); } #endif #if VITA if (videoType == VideoTypes.Vita) { api = new Vita.RenderTarget(parent, filename, width, height, generateMipmaps, multiSampleType, surfaceFormat, depthStencilFormat, renderTargetUsage, usage, loadedCallback); } #endif if (api == null) { Debug.ThrowError("RenderTargetAPI", "Unsuported InputType: " + videoType); } return(api); }
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; } }
public RenderTarget(IDisposableResource parent, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, DepthStencilFormats depthStencilFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, Loader.LoadedCallbackMethod loadedCallback) : base(parent, image, width, height, generateMipmaps, multiSampleType, surfaceFormat, renderTargetUsage, usage, loadedCallback) { if (initSuccess) { initDepthStencil(width, height, depthStencilFormat); } }
public RenderTarget(DisposableI parent, int width, int height, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, DepthStencilFormats depthStencilFormat, BufferUsages usage, RenderTargetUsage renderTargetUsage, Loader.LoadedCallbackMethod loadedCallback) : base(parent, width, height, surfaceFormat, usage, loadedCallback) { initDepthStencilFormat = depthStencilFormat; }
public static IRenderTarget New(IDisposableResource parent, int width, int height, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, DepthStencilFormats depthStencilFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, Loader.LoadedCallbackMethod loadedCallback) { return(New(VideoAPI.DefaultAPI, parent, (Image)null, width, height, false, multiSampleType, surfaceFormat, depthStencilFormat, renderTargetUsage, usage, loadedCallback)); }
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; } }
public RenderTarget(DisposableI parent, int width, int height, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, DepthStencilFormats depthStencilFormat, BufferUsages usage, RenderTargetUsage renderTargetUsage, Loader.LoadedCallbackMethod loadedCallback) : base(parent, width, height, surfaceFormat, usage, loadedCallback) { initDepthStencilFormat = depthStencilFormat; }