protected override void CreateFrameBuffer() { ColorFormat requestedColorFormat = 32; switch (RequestedBackBufferFormat) { case PixelFormat.R8G8B8A8_UNorm: case PixelFormat.B8G8R8A8_UNorm: requestedColorFormat = 32; break; case PixelFormat.B8G8R8X8_UNorm: requestedColorFormat = 24; break; case PixelFormat.B5G6R5_UNorm: requestedColorFormat = new ColorFormat(5, 6, 5, 0); break; case PixelFormat.B5G5R5A1_UNorm: requestedColorFormat = new ColorFormat(5, 5, 5, 1); break; default: throw new NotSupportedException("RequestedBackBufferFormat"); } // Query first the maximum supported profile, as some devices are crashing if we try to instantiate a 3.0 on a device supporting only 2.0 var maximumVersion = GetMaximumSupportedProfile(); foreach (var profile in RequestedGraphicsProfile) { var version = OpenGLUtils.GetGLVersion(profile); if (version > maximumVersion) { continue; } ContextRenderingApi = version; GraphicsMode = new GraphicsMode(requestedColorFormat, 0, 0); base.CreateFrameBuffer(); return; } throw new Exception("Unable to create a graphics context on the device. Maybe you should lower the preferred GraphicsProfile."); }
protected override void Initialize(GameContext <iOSWindow> gameContext) { gameForm = gameContext.Control.GameView; nativeWindow = new WindowHandle(AppContextType.iOS, gameForm); gameForm.Load += gameForm_Load; gameForm.Unload += gameForm_Unload; gameForm.RenderFrame += gameForm_RenderFrame; // get the OpenGL ES version var contextAvailable = false; foreach (var version in OpenGLUtils.GetGLVersions(gameContext.RequestedGraphicsProfile)) { var contextRenderingApi = MajorVersionTOEAGLRenderingAPI(version); EAGLContext contextTest = null; try { contextTest = new EAGLContext(contextRenderingApi); // delete extra context if (contextTest != null) { contextTest.Dispose(); } gameForm.ContextRenderingApi = contextRenderingApi; contextAvailable = true; break; } catch (Exception) { // TODO: log message } } if (!contextAvailable) { throw new Exception("Graphics context could not be created."); } gameForm.LayerColorFormat = EAGLColorFormat.RGBA8; //gameForm.LayerRetainsBacking = false; }
static List <DisplayVertex> CreateDisplayVertices(FMDL model, FSHP mesh) { // rearrange faces mesh.display = mesh.lodMeshes[mesh.DisplayLODIndex].getDisplayFace().ToArray(); List <DisplayVertex> displayVertList = new List <DisplayVertex>(); if (mesh.lodMeshes[mesh.DisplayLODIndex].faces.Count <= 3) { return(displayVertList); } foreach (Vertex v in mesh.vertices) { model.MaxPosition = OpenGLUtils.GetMax(model.MaxPosition, v.pos); model.MinPosition = OpenGLUtils.GetMin(model.MinPosition, v.pos); DisplayVertex displayVert = new DisplayVertex() { Position = v.pos, Normal = v.nrm, Color0 = v.col, Color1 = v.col2, TexCoord0 = v.uv0, TexCoord1 = v.uv1, TexCoord2 = v.uv2, BlendIndex = new Vector4( v.boneIds.Count > 0 ? v.boneIds[0] : -1, v.boneIds.Count > 1 ? v.boneIds[1] : -1, v.boneIds.Count > 2 ? v.boneIds[2] : -1, v.boneIds.Count > 3 ? v.boneIds[3] : -1), BlendWeight = new Vector4( v.boneWeights.Count > 0 ? v.boneWeights[0] : 0, v.boneWeights.Count > 1 ? v.boneWeights[1] : 0, v.boneWeights.Count > 2 ? v.boneWeights[2] : 0, v.boneWeights.Count > 3 ? v.boneWeights[3] : 0), }; displayVertList.Add(displayVert); } return(displayVertList); }
internal GraphicsDeviceFeatures(GraphicsDevice deviceRoot) { mapFeaturesPerFormat = new FeaturesPerFormat[256]; HasSRgb = true; using (deviceRoot.UseOpenGLCreationContext()) { Vendor = GL.GetString(StringName.Vendor); Renderer = GL.GetString(StringName.Renderer); #if SILICONSTUDIO_XENKO_GRAPHICS_API_OPENGLES SupportedExtensions = GL.GetString(StringName.Extensions).Split(' '); #else int numExtensions; GL.GetInteger(GetPName.NumExtensions, out numExtensions); SupportedExtensions = new string[numExtensions]; for (int extensionIndex = 0; extensionIndex < numExtensions; ++extensionIndex) { SupportedExtensions[extensionIndex] = GL.GetString(StringNameIndexed.Extensions, extensionIndex); } #endif } #if SILICONSTUDIO_XENKO_GRAPHICS_API_OPENGLES var isOpenGLES3 = deviceRoot.currentVersion >= 300; deviceRoot.HasDepth24 = isOpenGLES3 || SupportedExtensions.Contains("GL_OES_depth24"); deviceRoot.HasPackedDepthStencilExtension = SupportedExtensions.Contains("GL_OES_packed_depth_stencil"); deviceRoot.HasExtTextureFormatBGRA8888 = SupportedExtensions.Contains("GL_EXT_texture_format_BGRA8888") || SupportedExtensions.Contains("GL_APPLE_texture_format_BGRA8888"); deviceRoot.HasRenderTargetFloat = SupportedExtensions.Contains("GL_EXT_color_buffer_float"); deviceRoot.HasRenderTargetHalf = SupportedExtensions.Contains("GL_EXT_color_buffer_half_float"); deviceRoot.HasVAO = isOpenGLES3 || SupportedExtensions.Contains("GL_OES_vertex_array_object"); deviceRoot.HasTextureRG = isOpenGLES3 || SupportedExtensions.Contains("GL_EXT_texture_rg"); deviceRoot.HasKhronosDebug = deviceRoot.currentVersion >= 320 || SupportedExtensions.Contains("GL_KHR_debug"); // Either 3.2+, or 3.1+ with GL_EXT_texture_buffer // TODO: For now we don't have proper ES3 bindings on Android (and possibly iOS) deviceRoot.HasTextureBuffers = false; //deviceRoot.HasTextureBuffers = (deviceRoot.version >= 320) // || (deviceRoot.version >= 310 && SupportedExtensions.Contains("GL_EXT_texture_buffer")); HasSRgb = isOpenGLES3 || SupportedExtensions.Contains("GL_EXT_sRGB"); // Compute shaders available in OpenGL ES 3.1 HasComputeShaders = isOpenGLES3 && deviceRoot.currentVersion >= 1; HasDoublePrecision = false; HasDepthAsSRV = isOpenGLES3; HasDepthAsReadOnlyRT = isOpenGLES3; // TODO: from 3.1: draw indirect, separate shader object // TODO: check tessellation & geometry shaders: GL_ANDROID_extension_pack_es31a #else deviceRoot.HasVAO = true; deviceRoot.HasDXT = SupportedExtensions.Contains("GL_EXT_texture_compression_s3tc"); deviceRoot.HasTextureBuffers = true; deviceRoot.HasKhronosDebug = deviceRoot.currentVersion >= 430 || SupportedExtensions.Contains("GL_KHR_debug"); // Compute shaders available in OpenGL 4.3 HasComputeShaders = deviceRoot.version >= 430; HasDoublePrecision = SupportedExtensions.Contains("GL_ARB_vertex_attrib_64bit"); HasDepthAsSRV = deviceRoot.version >= 300; HasDepthAsReadOnlyRT = deviceRoot.version >= 300; // TODO: from 4.0: tessellation, draw indirect // TODO: from 4.1: separate shader object #endif deviceRoot.HasDepthClamp = SupportedExtensions.Contains("GL_ARB_depth_clamp"); HasDriverCommandLists = false; HasMultiThreadingConcurrentResources = false; // TODO: Enum supported formats in mapFeaturesPerFormat // Find shader model based on OpenGL version (might need to check extensions more carefully) RequestedProfile = deviceRoot.requestedGraphicsProfile; CurrentProfile = OpenGLUtils.GetFeatureLevel(deviceRoot.currentVersion); }
internal GraphicsDeviceFeatures(GraphicsDevice deviceRoot) { mapFeaturesPerFormat = new FeaturesPerFormat[256]; HasSRgb = true; using (deviceRoot.UseOpenGLCreationContext()) { Vendor = GL.GetString(StringName.Vendor); Renderer = GL.GetString(StringName.Renderer); #if SILICONSTUDIO_XENKO_GRAPHICS_API_OPENGLES SupportedExtensions = GL.GetString(StringName.Extensions).Split(' '); #else int numExtensions; GL.GetInteger(GetPName.NumExtensions, out numExtensions); SupportedExtensions = new string[numExtensions]; for (int extensionIndex = 0; extensionIndex < numExtensions; ++extensionIndex) { SupportedExtensions[extensionIndex] = GL.GetString(StringNameIndexed.Extensions, extensionIndex); } #endif } #if SILICONSTUDIO_XENKO_GRAPHICS_API_OPENGLES var isOpenGLES3 = deviceRoot.versionMajor >= 3; deviceRoot.HasDepth24 = isOpenGLES3 || SupportedExtensions.Contains("GL_OES_depth24"); deviceRoot.HasPackedDepthStencilExtension = SupportedExtensions.Contains("GL_OES_packed_depth_stencil"); deviceRoot.HasExtTextureFormatBGRA8888 = SupportedExtensions.Contains("GL_EXT_texture_format_BGRA8888") || SupportedExtensions.Contains("GL_APPLE_texture_format_BGRA8888"); deviceRoot.HasRenderTargetFloat = SupportedExtensions.Contains("GL_EXT_color_buffer_float"); deviceRoot.HasRenderTargetHalf = SupportedExtensions.Contains("GL_EXT_color_buffer_half_float"); deviceRoot.HasVAO = isOpenGLES3 || SupportedExtensions.Contains("GL_OES_vertex_array_object"); deviceRoot.HasTextureRG = isOpenGLES3 || SupportedExtensions.Contains("GL_EXT_texture_rg"); HasSRgb = isOpenGLES3 || SupportedExtensions.Contains("GL_EXT_sRGB"); // Compute shaders available in OpenGL ES 3.1 HasComputeShaders = isOpenGLES3 && deviceRoot.versionMinor >= 1; HasDoublePrecision = false; // TODO: from 3.1: draw indirect, separate shader object // TODO: check tessellation & geometry shaders: GL_ANDROID_extension_pack_es31a #else deviceRoot.HasVAO = true; // Compute shaders available in OpenGL 4.3 HasComputeShaders = deviceRoot.versionMajor >= 4 && deviceRoot.versionMinor >= 3; HasDoublePrecision = SupportedExtensions.Contains("GL_ARB_vertex_attrib_64bit"); // TODO: from 4.0: tessellation, draw indirect // TODO: from 4.1: separate shader object #endif HasDriverCommandLists = false; HasMultiThreadingConcurrentResources = false; // TODO: Enum supported formats in mapFeaturesPerFormat // Find shader model based on OpenGL version (might need to check extensions more carefully) Profile = OpenGLUtils.GetFeatureLevel(deviceRoot.versionMajor, deviceRoot.versionMinor); }
/// <summary> /// Initializes a new instance of the <see cref="GameContext" /> class. /// </summary> /// <param name="control">The control.</param> /// <param name="requestedWidth">Width of the requested.</param> /// <param name="requestedHeight">Height of the requested.</param> public GameContext(OpenTK.GameWindow control, int requestedWidth = 0, int requestedHeight = 0) { var creationFlags = GraphicsContextFlags.Default; #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES creationFlags |= GraphicsContextFlags.Embedded; #endif if (requestedWidth == 0 || requestedHeight == 0) { requestedWidth = 1280; requestedHeight = 720; } // force the stencil buffer to be not null. var defaultMode = GraphicsMode.Default; var graphicMode = new GraphicsMode(defaultMode.ColorFormat, defaultMode.Depth, 8, defaultMode.Samples, defaultMode.AccumulatorFormat, defaultMode.Buffers, defaultMode.Stereo); GraphicsContext.ShareContexts = true; if (control == null) { int versionMajor, versionMinor; if (RequestedGraphicsProfile == null || RequestedGraphicsProfile.Length == 0) { #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES versionMajor = 3; versionMinor = 0; #else // PC: 4.3 is commonly available (= compute shaders) // MacOS X: 4.1 maximum versionMajor = 4; versionMinor = 1; #endif Control = TryGameWindow(requestedWidth, requestedHeight, graphicMode, versionMajor, versionMinor, creationFlags); } else { foreach (var profile in RequestedGraphicsProfile) { OpenGLUtils.GetGLVersion(profile, out versionMajor, out versionMinor); var gameWindow = TryGameWindow(requestedWidth, requestedHeight, graphicMode, versionMajor, versionMinor, creationFlags); if (gameWindow != null) { Control = gameWindow; break; } } } } else { Control = control; } if (Control == null) { throw new Exception("Unable to initialize graphics context."); } RequestedWidth = requestedWidth; RequestedHeight = requestedHeight; ContextType = AppContextType.DesktopOpenTK; }
protected override void CreateFrameBuffer() { int requestedDepth = 0; int requestedStencil = 0; ColorFormat requestedColorFormat = 32; switch (RequestedBackBufferFormat) { case PixelFormat.R8G8B8A8_UNorm: case PixelFormat.B8G8R8A8_UNorm: requestedColorFormat = 32; break; case PixelFormat.B8G8R8X8_UNorm: requestedColorFormat = 24; break; case PixelFormat.B5G6R5_UNorm: requestedColorFormat = new ColorFormat(5, 6, 5, 0); break; case PixelFormat.B5G5R5A1_UNorm: requestedColorFormat = new ColorFormat(5, 5, 5, 1); break; default: throw new NotSupportedException("RequestedBackBufferFormat"); } switch (RequestedDepthStencilFormat) { case PixelFormat.None: break; case PixelFormat.D16_UNorm: requestedDepth = 16; break; case PixelFormat.D24_UNorm_S8_UInt: requestedDepth = 24; requestedStencil = 8; break; case PixelFormat.D32_Float: requestedDepth = 32; break; case PixelFormat.D32_Float_S8X24_UInt: requestedDepth = 32; requestedStencil = 8; break; default: throw new NotSupportedException("RequestedDepthStencilFormat"); } // Some devices only allow D16_S8, let's try it as well // D24 and D32 are supported on OpenGL ES 3 devices var requestedDepthFallback = requestedDepth > 16 ? 16 : requestedDepth; foreach (var version in OpenGLUtils.GetGLVersions(RequestedGraphicsProfile)) { if (TryCreateFrameBuffer(MajorVersionToGLVersion(version), requestedColorFormat, requestedDepth, requestedStencil) || TryCreateFrameBuffer(MajorVersionToGLVersion(version), requestedColorFormat, requestedDepthFallback, requestedStencil)) { return; } } throw new Exception("Unable to create a graphics context on the device. Maybe you should lower the preferred GraphicsProfile."); }
internal GraphicsDeviceFeatures(GraphicsDevice deviceRoot) { mapFeaturesPerFormat = new FeaturesPerFormat[256]; HasSRgb = true; using (deviceRoot.UseOpenGLCreationContext()) { Vendor = GL.GetString(StringName.Vendor); Renderer = GL.GetString(StringName.Renderer); #if STRIDE_GRAPHICS_API_OPENGLES SupportedExtensions = GL.GetString(StringName.Extensions).Split(' '); #else int numExtensions; GL.GetInteger(GetPName.NumExtensions, out numExtensions); SupportedExtensions = new string[numExtensions]; for (int extensionIndex = 0; extensionIndex < numExtensions; ++extensionIndex) { SupportedExtensions[extensionIndex] = GL.GetString(StringNameIndexed.Extensions, extensionIndex); } #endif } #if STRIDE_GRAPHICS_API_OPENGLES deviceRoot.HasExtTextureFormatBGRA8888 = SupportedExtensions.Contains("GL_EXT_texture_format_BGRA8888") || SupportedExtensions.Contains("GL_APPLE_texture_format_BGRA8888"); deviceRoot.HasKhronosDebug = deviceRoot.currentVersion >= 320 || SupportedExtensions.Contains("GL_KHR_debug"); deviceRoot.HasTimerQueries = SupportedExtensions.Contains("GL_EXT_disjoint_timer_query"); // Either 3.2+, or 3.1+ with GL_EXT_texture_buffer // TODO: For now we don't have proper ES3 bindings on Android (and possibly iOS) deviceRoot.HasTextureBuffers = false; //deviceRoot.HasTextureBuffers = (deviceRoot.version >= 320) // || (deviceRoot.version >= 310 && SupportedExtensions.Contains("GL_EXT_texture_buffer")); // Compute shaders available in OpenGL ES 3.1 HasComputeShaders = deviceRoot.currentVersion >= 310; HasDoublePrecision = false; HasDepthAsSRV = true; HasDepthAsReadOnlyRT = true; HasMultisampleDepthAsSRV = true; deviceRoot.HasDepthClamp = SupportedExtensions.Contains("GL_ARB_depth_clamp"); // TODO: from 3.1: draw indirect, separate shader object // TODO: check tessellation & geometry shaders: GL_ANDROID_extension_pack_es31a #else deviceRoot.HasDXT = SupportedExtensions.Contains("GL_EXT_texture_compression_s3tc"); deviceRoot.HasTextureBuffers = true; deviceRoot.HasKhronosDebug = deviceRoot.currentVersion >= 430 || SupportedExtensions.Contains("GL_KHR_debug"); deviceRoot.HasTimerQueries = deviceRoot.version >= 320; // Compute shaders available in OpenGL 4.3 HasComputeShaders = deviceRoot.version >= 430; HasDoublePrecision = SupportedExtensions.Contains("GL_ARB_vertex_attrib_64bit"); HasDepthAsSRV = true; HasDepthAsReadOnlyRT = true; HasMultisampleDepthAsSRV = true; deviceRoot.HasDepthClamp = true; // TODO: from 4.0: tessellation, draw indirect // TODO: from 4.1: separate shader object #endif deviceRoot.HasAnisotropicFiltering = SupportedExtensions.Contains("GL_EXT_texture_filter_anisotropic"); HasResourceRenaming = true; HasDriverCommandLists = false; HasMultiThreadingConcurrentResources = false; // Find shader model based on OpenGL version (might need to check extensions more carefully) RequestedProfile = deviceRoot.requestedGraphicsProfile; CurrentProfile = OpenGLUtils.GetFeatureLevel(deviceRoot.currentVersion); EnumerateMSAASupportPerFormat(deviceRoot); }
internal override void Initialize(GameContext gameContext) { GameContext = gameContext; gameForm = gameContext.GameView; nativeWindow = new WindowHandle(AppContextType.iOS, gameForm); gameForm.Load += gameForm_Load; gameForm.Unload += gameForm_Unload; gameForm.RenderFrame += gameForm_RenderFrame; // get the OpenGL ES version var contextAvailable = false; foreach (var version in OpenGLUtils.GetGLVersions(gameContext.RequestedGraphicsProfile)) { var contextRenderingApi = MajorVersionTOEAGLRenderingAPI(version); EAGLContext contextTest = null; try { contextTest = new EAGLContext(contextRenderingApi); // delete extra context if (contextTest != null) { contextTest.Dispose(); } gameForm.ContextRenderingApi = contextRenderingApi; contextAvailable = true; } catch (Exception) { // TODO: log message } } if (!contextAvailable) { throw new Exception("Graphics context could not be created."); } gameForm.LayerColorFormat = MonoTouch.OpenGLES.EAGLColorFormat.RGBA8; //gameForm.LayerRetainsBacking = false; // Setup the initial size of the window var width = gameContext.RequestedWidth; if (width == 0) { width = (int)(gameForm.Size.Width * gameForm.ContentScaleFactor); } var height = gameContext.RequestedHeight; if (height == 0) { height = (int)(gameForm.Size.Height * gameForm.ContentScaleFactor); } gameForm.Size = new Size(width, height); //gameForm.Resize += OnClientSizeChanged; }
internal GraphicsAdapter() { outputs = new [] { new GraphicsOutput() }; // set default values int detectedVersion = 100; string renderer, vendor, version; int versionMajor, versionMinor; var SDL = Stride.Graphics.SDL.Window.SDL; // Some platforms (i.e. Android) can only have a single window var sdlWindow = DefaultWindow; if (sdlWindow == null) { sdlWindow = SDL.CreateWindow("Stride Hidden OpenGL", 50, 50, 1280, 720, (uint)(WindowFlags.WindowHidden | WindowFlags.WindowOpengl)); } using (var sdlContext = new SdlContext(SDL, sdlWindow)) using (var gl = GL.GetApi(sdlContext)) { #if STRIDE_GRAPHICS_API_OPENGLES SDL.GLSetAttribute(GLattr.GLContextProfileMask, (int)GLprofile.GLContextProfileES); #else SDL.GLSetAttribute(GLattr.GLContextProfileMask, (int)GLprofile.GLContextProfileCore); #endif sdlContext.Create(); renderer = gl.GetStringS(StringName.Renderer); vendor = gl.GetStringS(StringName.Vendor); version = gl.GetStringS(StringName.Version); gl.GetInteger(GetPName.MajorVersion, out versionMajor); gl.GetInteger(GetPName.MinorVersion, out versionMinor); } if (sdlWindow != DefaultWindow) { SDL.DestroyWindow(sdlWindow); } // Stay close to D3D: Cut renderer after first / (ex: "GeForce 670/PCIe/SSE2") var rendererSlash = renderer.IndexOf('/'); if (rendererSlash != -1) { renderer = renderer.Substring(0, rendererSlash); } // Stay close to D3D: Remove "Corporation" from vendor vendor = vendor.Replace(" Corporation", string.Empty); // Generate adapter Description Description = $"{vendor} {renderer}"; // get real values // Note: using glGetIntegerv(GL_MAJOR_VERSION / GL_MINOR_VERSION) only works on opengl (es) >= 3.0 detectedVersion = versionMajor * 100 + versionMinor * 10; supportedGraphicsProfile = OpenGLUtils.GetFeatureLevel(detectedVersion); OpenGLVersion = detectedVersion; OpenGLRenderer = renderer; }