/// <summary> /// Initializes a new instance of the OpenGLUltravioletGraphics class. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <param name="configuration">The Ultraviolet Framework configuration settings for the current context.</param> public OpenGLUltravioletGraphics(OpenGLUltravioletContext uv, UltravioletConfiguration configuration) : base(uv) { if (configuration.Debug) { SDL.GL_SetAttribute(SDL_GLattr.CONTEXT_FLAGS, (int)SDL_GLcontextFlag.DEBUG); } var masterptr = ((OpenGLUltravioletWindowInfo)uv.GetPlatform().Windows).GetMasterPointer(); if ((this.context = SDL.GL_CreateContext(masterptr)) == IntPtr.Zero) throw new SDL2Exception(); if (SDL.GL_SetSwapInterval(0) < 0) throw new SDL2Exception(); if (gl.Initialized) { gl.Uninitialize(); } gl.Initialize(new OpenGLInitializer()); OpenGLState.ResetCache(); if (!VerifyCapabilities()) throw new NotSupportedException(OpenGLStrings.UnsupportedGraphicsDevice); if (configuration.Debug && configuration.DebugCallback != null) { InitializeDebugOutput(configuration); } this.maxTextureStages = Math.Min(16, gl.GetInteger(gl.GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS)); this.textures = new Texture2D[maxTextureStages]; this.samplerStates = new SamplerState[maxTextureStages]; this.capabilities = new OpenGLGraphicsCapabilities(); ResetDeviceStates(); }
/// <summary> /// Initializes a new instance of the OpenGLUltravioletGraphics class. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <param name="configuration">The Ultraviolet Framework configuration settings for the current context.</param> public OpenGLUltravioletGraphics(OpenGLUltravioletContext uv, UltravioletConfiguration configuration) : base(uv) { if (configuration.Debug) { SDL.GL_SetAttribute(SDL_GLattr.CONTEXT_FLAGS, (int)SDL_GLcontextFlag.DEBUG); } var masterptr = ((OpenGLUltravioletWindowInfo)uv.GetPlatform().Windows).GetMasterPointer(); if ((this.context = SDL.GL_CreateContext(masterptr)) == IntPtr.Zero) { if (configuration.Debug) { SDL.GL_SetAttribute(SDL_GLattr.CONTEXT_FLAGS, 0); if ((this.context = SDL.GL_CreateContext(masterptr)) == IntPtr.Zero) { throw new SDL2Exception(); } } else { throw new SDL2Exception(); } } if (SDL.GL_SetSwapInterval(1) < 0) { throw new SDL2Exception(); } if (gl.Initialized) { gl.Uninitialize(); } gl.Initialize(new OpenGLInitializer()); OpenGLState.ResetCache(); if (!VerifyCapabilities()) { throw new NotSupportedException(OpenGLStrings.UnsupportedGraphicsDevice); } if (configuration.Debug && configuration.DebugCallback != null) { InitializeDebugOutput(configuration); } this.capabilities = new OpenGLGraphicsCapabilities(); this.maxTextureStages = gl.GetInteger(gl.GL_MAX_TEXTURE_IMAGE_UNITS); this.textures = new Texture2D[maxTextureStages]; this.samplerStates = new SamplerState[maxTextureStages]; this.samplerObjects = capabilities.SupportsIndependentSamplerState ? new OpenGLSamplerObject[maxTextureStages] : null; this.backBufferRenderTargetUsage = configuration.BackBufferRenderTargetUsage; if (samplerObjects != null) { for (int i = 0; i < samplerObjects.Length; i++) { samplerObjects[i] = new OpenGLSamplerObject(Ultraviolet); samplerObjects[i].Bind((uint)i); } } OpenGLState.VerifyCache(); ResetDeviceStates(); }
public unsafe OpenGLUltravioletGraphics(OpenGLUltravioletContext uv, OpenGLUltravioletConfiguration configuration, Version versionRequested) : base(uv) { var masterptr = ((OpenGLUltravioletWindowInfo)uv.GetPlatform().Windows).GetMasterPointer(); if (!TryInitializeGLContext(masterptr, configuration)) { var attemptedVersionMajor = 0; var attemptedVersionMinor = 0; if (SDL.GL_GetAttribute(SDL_GLattr.CONTEXT_MAJOR_VERSION, &attemptedVersionMajor) < 0) throw new SDL2Exception(); if (SDL.GL_GetAttribute(SDL_GLattr.CONTEXT_MINOR_VERSION, &attemptedVersionMinor) < 0) throw new SDL2Exception(); var attemptedVersion = new Version(attemptedVersionMajor, attemptedVersionMinor, 0, 0); var isGLES = (uv.Platform == UltravioletPlatform.Android || uv.Platform == UltravioletPlatform.iOS); if (isGLES && attemptedVersion >= new Version(3, 0) && (configuration.MinimumOpenGLESVersion ?? new Version(2, 0)) <= new Version(2, 0)) { if (SDL.GL_SetAttribute(SDL_GLattr.CONTEXT_MAJOR_VERSION, 2) < 0) throw new SDL2Exception(); if (SDL.GL_SetAttribute(SDL_GLattr.CONTEXT_MINOR_VERSION, 0) < 0) throw new SDL2Exception(); if (!TryInitializeGLContext(masterptr, configuration)) throw new SDL2Exception(); } else throw new SDL2Exception(); } if (SDL.GL_SetSwapInterval(1) < 0 && uv.Platform != UltravioletPlatform.iOS) throw new SDL2Exception(); if (gl.Initialized) { gl.Uninitialize(); } gl.Initialize(new OpenGLInitializer()); if (!gl.IsVersionAtLeast(versionRequested)) throw new InvalidOperationException(OpenGLStrings.DoesNotMeetMinimumVersionRequirement.Format(gl.MajorVersion, gl.MinorVersion, versionRequested.Major, versionRequested.Minor)); OpenGLState.ResetCache(); if (!VerifyCapabilities()) throw new NotSupportedException(OpenGLStrings.UnsupportedGraphicsDevice); if (configuration.Debug && configuration.DebugCallback != null) { InitializeDebugOutput(configuration); } this.capabilities = new OpenGLGraphicsCapabilities(); this.maxTextureStages = gl.GetInteger(gl.GL_MAX_TEXTURE_IMAGE_UNITS); this.textures = new Texture2D[maxTextureStages]; this.samplerStates = new SamplerState[maxTextureStages]; this.samplerObjects = capabilities.SupportsIndependentSamplerState ? new OpenGLSamplerObject[maxTextureStages] : null; this.backBufferRenderTargetUsage = configuration.BackBufferRenderTargetUsage; if (samplerObjects != null) { for (int i = 0; i < samplerObjects.Length; i++) { samplerObjects[i] = new OpenGLSamplerObject(Ultraviolet); samplerObjects[i].Bind((uint)i); } } OpenGLState.VerifyCache(); }
public unsafe OpenGLUltravioletGraphics(OpenGLUltravioletContext uv, OpenGLUltravioletConfiguration configuration, Version versionRequested) : base(uv) { var masterptr = ((OpenGLUltravioletWindowInfo)uv.GetPlatform().Windows).GetMasterPointer(); if (!TryInitializeGLContext(masterptr, configuration)) { var attemptedVersionMajor = 0; var attemptedVersionMinor = 0; if (SDL.GL_GetAttribute(SDL_GLattr.CONTEXT_MAJOR_VERSION, &attemptedVersionMajor) < 0) { throw new SDL2Exception(); } if (SDL.GL_GetAttribute(SDL_GLattr.CONTEXT_MINOR_VERSION, &attemptedVersionMinor) < 0) { throw new SDL2Exception(); } var attemptedVersion = new Version(attemptedVersionMajor, attemptedVersionMinor, 0, 0); var isGLES = (uv.Platform == UltravioletPlatform.Android || uv.Platform == UltravioletPlatform.iOS); if (isGLES && attemptedVersion >= new Version(3, 0) && (configuration.MinimumOpenGLESVersion ?? new Version(2, 0)) <= new Version(2, 0)) { if (SDL.GL_SetAttribute(SDL_GLattr.CONTEXT_MAJOR_VERSION, 2) < 0) { throw new SDL2Exception(); } if (SDL.GL_SetAttribute(SDL_GLattr.CONTEXT_MINOR_VERSION, 0) < 0) { throw new SDL2Exception(); } if (!TryInitializeGLContext(masterptr, configuration)) { throw new SDL2Exception(); } } else { throw new SDL2Exception(); } } if (SDL.GL_SetSwapInterval(1) < 0 && uv.Platform != UltravioletPlatform.iOS) { throw new SDL2Exception(); } if (gl.Initialized) { gl.Uninitialize(); } gl.Initialize(new OpenGLInitializer()); if (!gl.IsVersionAtLeast(versionRequested)) { throw new InvalidOperationException(OpenGLStrings.DoesNotMeetMinimumVersionRequirement.Format(gl.MajorVersion, gl.MinorVersion, versionRequested.Major, versionRequested.Minor)); } OpenGLState.ResetCache(); if (!VerifyCapabilities()) { throw new NotSupportedException(OpenGLStrings.UnsupportedGraphicsDevice); } if (configuration.Debug && configuration.DebugCallback != null) { InitializeDebugOutput(configuration); } this.capabilities = new OpenGLGraphicsCapabilities(configuration); this.maxTextureStages = gl.GetInteger(gl.GL_MAX_TEXTURE_IMAGE_UNITS); this.textures = new Texture2D[maxTextureStages]; this.samplerStates = new SamplerState[maxTextureStages]; this.samplerObjects = capabilities.SupportsIndependentSamplerState ? new OpenGLSamplerObject[maxTextureStages] : null; this.backBufferRenderTargetUsage = configuration.BackBufferRenderTargetUsage; if (samplerObjects != null) { for (int i = 0; i < samplerObjects.Length; i++) { samplerObjects[i] = new OpenGLSamplerObject(Ultraviolet); samplerObjects[i].Bind((uint)i); } } OpenGLState.VerifyCache(); }