private void LoadGLEntryPoints() { /* Basic entry points. If you don't have these, you're screwed. */ try { INTERNAL_glGetString = (GetString) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGetString"), typeof(GetString) ); glGetIntegerv = (GetIntegerv) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGetIntegerv"), typeof(GetIntegerv) ); glEnable = (Enable) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glEnable"), typeof(Enable) ); glDisable = (Disable) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDisable"), typeof(Disable) ); glViewport = (G_Viewport) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glViewport"), typeof(G_Viewport) ); glDepthRange = (DepthRange) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDepthRange"), typeof(DepthRange) ); glScissor = (Scissor) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glScissor"), typeof(Scissor) ); glBlendColor = (BlendColor) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glBlendColor"), typeof(BlendColor) ); glBlendFuncSeparate = (BlendFuncSeparate) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glBlendFuncSeparate"), typeof(BlendFuncSeparate) ); glBlendEquationSeparate = (BlendEquationSeparate) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glBlendEquationSeparate"), typeof(BlendEquationSeparate) ); glColorMask = (ColorMask) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glColorMask"), typeof(ColorMask) ); glDepthMask = (DepthMask) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDepthMask"), typeof(DepthMask) ); glDepthFunc = (DepthFunc) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDepthFunc"), typeof(DepthFunc) ); glStencilMask = (StencilMask) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glStencilMask"), typeof(StencilMask) ); glStencilFuncSeparate = (StencilFuncSeparate) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glStencilFuncSeparate"), typeof(StencilFuncSeparate) ); glStencilOpSeparate = (StencilOpSeparate) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glStencilOpSeparate"), typeof(StencilOpSeparate) ); glStencilFunc = (StencilFunc) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glStencilFunc"), typeof(StencilFunc) ); glStencilOp = (StencilOp) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glStencilOp"), typeof(StencilOp) ); glCullFace = (CullFace) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glCullFace"), typeof(CullFace) ); glFrontFace = (FrontFace) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glFrontFace"), typeof(FrontFace) ); glPolygonMode = (PolygonMode) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glPolygonMode"), typeof(PolygonMode) ); glPolygonOffset = (PolygonOffset) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glPolygonOffset"), typeof(PolygonOffset) ); glGenTextures = (GenTextures) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGenTextures"), typeof(GenTextures) ); glDeleteTextures = (DeleteTextures) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDeleteTextures"), typeof(DeleteTextures) ); glBindTexture = (G_BindTexture) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glBindTexture"), typeof(G_BindTexture) ); glTexImage2D = (TexImage2D) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glTexImage2D"), typeof(TexImage2D) ); glTexSubImage2D = (TexSubImage2D) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glTexSubImage2D"), typeof(TexSubImage2D) ); glCompressedTexImage2D = (CompressedTexImage2D) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glCompressedTexImage2D"), typeof(CompressedTexImage2D) ); glCompressedTexSubImage2D = (CompressedTexSubImage2D) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glCompressedTexSubImage2D"), typeof(CompressedTexSubImage2D) ); glTexImage3D = (TexImage3D) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glTexImage3D"), typeof(TexImage3D) ); glTexSubImage3D = (TexSubImage3D) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glTexSubImage3D"), typeof(TexSubImage3D) ); glGetTexImage = (GetTexImage) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGetTexImage"), typeof(GetTexImage) ); glTexParameteri = (TexParameteri) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glTexParameteri"), typeof(TexParameteri) ); glTexParameterf = (TexParameterf) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glTexParameterf"), typeof(TexParameterf) ); glActiveTexture = (ActiveTexture) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glActiveTexture"), typeof(ActiveTexture) ); glPixelStorei = (PixelStorei) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glPixelStorei"), typeof(PixelStorei) ); glGenBuffers = (GenBuffers) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGenBuffers"), typeof(GenBuffers) ); glDeleteBuffers = (DeleteBuffers) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDeleteBuffers"), typeof(DeleteBuffers) ); glBindBuffer = (BindBuffer) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glBindBuffer"), typeof(BindBuffer) ); glBufferData = (BufferData) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glBufferData"), typeof(BufferData) ); glBufferSubData = (BufferSubData) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glBufferSubData"), typeof(BufferSubData) ); glMapBuffer = (MapBuffer) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glMapBuffer"), typeof(MapBuffer) ); glUnmapBuffer = (UnmapBuffer) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glUnmapBuffer"), typeof(UnmapBuffer) ); glClearColor = (ClearColor) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glClearColor"), typeof(ClearColor) ); glClearDepth = (ClearDepth) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glClearDepth"), typeof(ClearDepth) ); glClearStencil = (ClearStencil) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glClearStencil"), typeof(ClearStencil) ); glClear = (G_Clear) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glClear"), typeof(G_Clear) ); glDrawBuffers = (DrawBuffers) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDrawBuffers"), typeof(DrawBuffers) ); glReadPixels = (ReadPixels) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glReadPixels"), typeof(ReadPixels) ); glVertexAttribPointer = (VertexAttribPointer) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glVertexAttribPointer"), typeof(VertexAttribPointer) ); glEnableVertexAttribArray = (EnableVertexAttribArray) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glEnableVertexAttribArray"), typeof(EnableVertexAttribArray) ); glDisableVertexAttribArray = (DisableVertexAttribArray) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDisableVertexAttribArray"), typeof(DisableVertexAttribArray) ); glDrawRangeElements = (DrawRangeElements) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDrawRangeElements"), typeof(DrawRangeElements) ); glDrawArrays = (DrawArrays) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDrawArrays"), typeof(DrawArrays) ); glGenQueries = (GenQueries) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGenQueries"), typeof(GenQueries) ); glDeleteQueries = (DeleteQueries) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDeleteQueries"), typeof(DeleteQueries) ); glBeginQuery = (BeginQuery) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glBeginQuery"), typeof(BeginQuery) ); glEndQuery = (EndQuery) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glEndQuery"), typeof(EndQuery) ); glGetQueryObjectiv = (GetQueryObjectiv) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGetQueryObjectiv"), typeof(GetQueryObjectiv) ); } catch { throw new NoSuitableGraphicsDeviceException("OpenGL 2.1 support is required!"); } /* ARB_framebuffer_object. We're flexible, but not _that_ flexible. */ try { glGenFramebuffers = (GenFramebuffers) Marshal.GetDelegateForFunctionPointer( TryGetFramebufferEP("glGenFramebuffers"), typeof(GenFramebuffers) ); glDeleteFramebuffers = (DeleteFramebuffers) Marshal.GetDelegateForFunctionPointer( TryGetFramebufferEP("glDeleteFramebuffers"), typeof(DeleteFramebuffers) ); glBindFramebuffer = (G_BindFramebuffer) Marshal.GetDelegateForFunctionPointer( TryGetFramebufferEP("glBindFramebuffer"), typeof(G_BindFramebuffer) ); glFramebufferTexture2D = (FramebufferTexture2D) Marshal.GetDelegateForFunctionPointer( TryGetFramebufferEP("glFramebufferTexture2D"), typeof(FramebufferTexture2D) ); glFramebufferRenderbuffer = (FramebufferRenderbuffer) Marshal.GetDelegateForFunctionPointer( TryGetFramebufferEP("glFramebufferRenderbuffer"), typeof(FramebufferRenderbuffer) ); glGenerateMipmap = (GenerateMipmap) Marshal.GetDelegateForFunctionPointer( TryGetFramebufferEP("glGenerateMipmap"), typeof(GenerateMipmap) ); #if !DISABLE_FAUXBACKBUFFER glBlitFramebuffer = (BlitFramebuffer) Marshal.GetDelegateForFunctionPointer( TryGetFramebufferEP("glBlitFramebuffer"), typeof(BlitFramebuffer) ); #endif glGenRenderbuffers = (GenRenderbuffers) Marshal.GetDelegateForFunctionPointer( TryGetFramebufferEP("glGenRenderbuffers"), typeof(GenRenderbuffers) ); glDeleteRenderbuffers = (DeleteRenderbuffers) Marshal.GetDelegateForFunctionPointer( TryGetFramebufferEP("glDeleteRenderbuffers"), typeof(DeleteRenderbuffers) ); glBindRenderbuffer = (BindRenderbuffer) Marshal.GetDelegateForFunctionPointer( TryGetFramebufferEP("glBindRenderbuffer"), typeof(BindRenderbuffer) ); glRenderbufferStorage = (RenderbufferStorage) Marshal.GetDelegateForFunctionPointer( TryGetFramebufferEP("glRenderbufferStorage"), typeof(RenderbufferStorage) ); } catch { throw new NoSuitableGraphicsDeviceException("OpenGL framebuffer support is required!"); } /* ARB_instanced_arrays/ARB_draw_instanced are almost optional. */ SupportsHardwareInstancing = true; try { glVertexAttribDivisor = (VertexAttribDivisor) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glVertexAttribDivisor"), typeof(VertexAttribDivisor) ); glDrawElementsInstanced = (DrawElementsInstanced) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDrawElementsInstanced"), typeof(DrawElementsInstanced) ); } catch { SupportsHardwareInstancing = false; } /* EXT_draw_buffers2 is probably used by nobody. */ try { glColorMaskIndexedEXT = (ColorMaskIndexedEXT) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glColorMaskIndexedEXT"), typeof(ColorMaskIndexedEXT) ); } catch { // FIXME: SupportsIndependentWriteMasks? -flibit } /* EXT_framebuffer_multisample/ARB_texture_multisample is glitter -flibit */ supportsMultisampling = true; try { glRenderbufferStorageMultisample = (RenderbufferStorageMultisample) Marshal.GetDelegateForFunctionPointer( TryGetFramebufferEP("glRenderbufferStorageMultisample"), typeof(RenderbufferStorageMultisample) ); glSampleMaski = (SampleMaski) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glSampleMaski"), typeof(SampleMaski) ); } catch { supportsMultisampling = false; } if (useCoreProfile) { try { INTERNAL_glGetStringi = (GetStringi) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGetStringi"), typeof(GetStringi) ); glGenVertexArrays = (GenVertexArrays) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGenVertexArrays"), typeof(GenVertexArrays) ); glDeleteVertexArrays = (DeleteVertexArrays) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDeleteVertexArrays"), typeof(DeleteVertexArrays) ); glBindVertexArray = (BindVertexArray) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glBindVertexArray"), typeof(BindVertexArray) ); } catch { throw new NoSuitableGraphicsDeviceException("OpenGL 3.2 support is required!"); } } #if DEBUG /* ARB_debug_output, for debug contexts */ IntPtr messageCallback = SDL.SDL_GL_GetProcAddress("glDebugMessageCallbackARB"); IntPtr messageControl = SDL.SDL_GL_GetProcAddress("glDebugMessageControlARB"); if (messageCallback == IntPtr.Zero || messageControl == IntPtr.Zero) { System.Console.WriteLine("ARB_debug_output not supported!"); } else { glDebugMessageCallbackARB = (DebugMessageCallback) Marshal.GetDelegateForFunctionPointer( messageCallback, typeof(DebugMessageCallback) ); glDebugMessageControlARB = (DebugMessageControl) Marshal.GetDelegateForFunctionPointer( messageControl, typeof(DebugMessageControl) ); glDebugMessageControlARB( GLenum.GL_DONT_CARE, GLenum.GL_DONT_CARE, GLenum.GL_DONT_CARE, 0, IntPtr.Zero, true ); glDebugMessageControlARB( GLenum.GL_DONT_CARE, GLenum.GL_DEBUG_TYPE_OTHER_ARB, GLenum.GL_DEBUG_SEVERITY_LOW_ARB, 0, IntPtr.Zero, false ); glDebugMessageControlARB( GLenum.GL_DONT_CARE, GLenum.GL_DEBUG_TYPE_OTHER_ARB, GLenum.GL_DEBUG_SEVERITY_NOTIFICATION_ARB, 0, IntPtr.Zero, false ); glDebugMessageCallbackARB(DebugCall, IntPtr.Zero); } /* GREMEDY_string_marker, for apitrace */ IntPtr stringMarkerCallback = SDL.SDL_GL_GetProcAddress("glStringMarkerGREMEDY"); if (stringMarkerCallback == IntPtr.Zero) { System.Console.WriteLine("GREMEDY_string_marker not supported!"); } else { glStringMarkerGREMEDY = (StringMarkerGREMEDY) Marshal.GetDelegateForFunctionPointer( stringMarkerCallback, typeof(StringMarkerGREMEDY) ); } #endif }
public static void Initialize(bool preferLegacyProfile) { try { // First set up the bindings we need for error handling glEnable = Bind <Enable>("glEnable"); glDisable = Bind <Disable>("glDisable"); glGetError = Bind <GetError>("glGetError"); glGetStringInternal = Bind <GetString>("glGetString"); glGetStringiInternal = Bind <GetStringi>("glGetStringi"); glGetIntegerv = Bind <GetIntegerv>("glGetIntegerv"); } catch (Exception e) { throw new InvalidProgramException("Failed to initialize low-level OpenGL bindings. GPU information is not available.", e); } if (!DetectGLFeatures(preferLegacyProfile)) { WriteGraphicsLog("Unsupported OpenGL version: " + glGetString(GL_VERSION)); throw new InvalidProgramException("OpenGL Version Error: See graphics.log for details."); } // Allow users to force-disable the debug message callback feature to work around driver bugs if (Features.HasFlag(GLFeatures.DebugMessagesCallback) && Game.Settings.Graphics.DisableGLDebugMessageCallback) { Features ^= GLFeatures.DebugMessagesCallback; } // Force disable the debug message callback feature on Linux + AMD GPU to work around a startup freeze if (Features.HasFlag(GLFeatures.DebugMessagesCallback) && Platform.CurrentPlatform == PlatformType.Linux) { var renderer = glGetString(GL_RENDERER); if (renderer.Contains("AMD") || renderer.Contains("Radeon")) { Features ^= GLFeatures.DebugMessagesCallback; } } // Older Intel on Windows is broken too if (Features.HasFlag(GLFeatures.DebugMessagesCallback) && Platform.CurrentPlatform == PlatformType.Windows) { var renderer = glGetString(GL_RENDERER); if (renderer.Contains("HD Graphics") && !renderer.Contains("UHD Graphics")) { Features ^= GLFeatures.DebugMessagesCallback; } } // Setup the debug message callback handler if (Features.HasFlag(GLFeatures.DebugMessagesCallback)) { try { var suffix = Profile == GLProfile.Embedded ? "KHR" : ""; glDebugMessageCallback = Bind <DebugMessageCallback>("glDebugMessageCallback" + suffix); glDebugMessageInsert = Bind <DebugMessageInsert>("glDebugMessageInsert" + suffix); glEnable(GL_DEBUG_OUTPUT); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); // Need to keep a reference to the callback so it doesn't get garbage collected DebugMessageHandle = DebugMessageHandler; glDebugMessageCallback(DebugMessageHandle, IntPtr.Zero); } catch (Exception e) { throw new InvalidProgramException("Failed to initialize an OpenGL debug message callback.", e); } } Console.WriteLine("OpenGL renderer: " + glGetString(GL_RENDERER)); Console.WriteLine("OpenGL version: " + glGetString(GL_VERSION)); try { glFlush = Bind <Flush>("glFlush"); glViewport = Bind <Viewport>("glViewport"); glClear = Bind <Clear>("glClear"); glClearColor = Bind <ClearColor>("glClearColor"); glFinish = Bind <Finish>("glFinish"); glCreateProgram = Bind <CreateProgram>("glCreateProgram"); glUseProgram = Bind <UseProgram>("glUseProgram"); glGetProgramiv = Bind <GetProgramiv>("glGetProgramiv"); glCreateShader = Bind <CreateShader>("glCreateShader"); glShaderSource = Bind <ShaderSource>("glShaderSource"); glCompileShader = Bind <CompileShader>("glCompileShader"); glGetShaderiv = Bind <GetShaderiv>("glGetShaderiv"); glAttachShader = Bind <AttachShader>("glAttachShader"); glGetShaderInfoLog = Bind <GetShaderInfoLog>("glGetShaderInfoLog"); glLinkProgram = Bind <LinkProgram>("glLinkProgram"); glGetProgramInfoLog = Bind <GetProgramInfoLog>("glGetProgramInfoLog"); glGetUniformLocation = Bind <GetUniformLocation>("glGetUniformLocation"); glGetActiveUniform = Bind <GetActiveUniform>("glGetActiveUniform"); glUniform1i = Bind <Uniform1i>("glUniform1i"); glUniform1f = Bind <Uniform1f>("glUniform1f"); glUniform2f = Bind <Uniform2f>("glUniform2f"); glUniform3f = Bind <Uniform3f>("glUniform3f"); glUniform1fv = Bind <Uniform1fv>("glUniform1fv"); glUniform2fv = Bind <Uniform2fv>("glUniform2fv"); glUniform3fv = Bind <Uniform3fv>("glUniform3fv"); glUniform4fv = Bind <Uniform4fv>("glUniform4fv"); glUniformMatrix4fv = Bind <UniformMatrix4fv>("glUniformMatrix4fv"); glGenBuffers = Bind <GenBuffers>("glGenBuffers"); glBindBuffer = Bind <BindBuffer>("glBindBuffer"); glBufferData = Bind <BufferData>("glBufferData"); glBufferSubData = Bind <BufferSubData>("glBufferSubData"); glDeleteBuffers = Bind <DeleteBuffers>("glDeleteBuffers"); glBindAttribLocation = Bind <BindAttribLocation>("glBindAttribLocation"); glVertexAttribPointer = Bind <VertexAttribPointer>("glVertexAttribPointer"); glEnableVertexAttribArray = Bind <EnableVertexAttribArray>("glEnableVertexAttribArray"); glDisableVertexAttribArray = Bind <DisableVertexAttribArray>("glDisableVertexAttribArray"); glDrawArrays = Bind <DrawArrays>("glDrawArrays"); glBlendEquation = Bind <BlendEquation>("glBlendEquation"); glBlendEquationSeparate = Bind <BlendEquationSeparate>("glBlendEquationSeparate"); glBlendFunc = Bind <BlendFunc>("glBlendFunc"); glDepthFunc = Bind <DepthFunc>("glDepthFunc"); glScissor = Bind <Scissor>("glScissor"); glReadPixels = Bind <ReadPixels>("glReadPixels"); glGenTextures = Bind <GenTextures>("glGenTextures"); glDeleteTextures = Bind <DeleteTextures>("glDeleteTextures"); glIsTexture = Bind <IsTexture>("glIsTexture"); glBindTexture = Bind <BindTexture>("glBindTexture"); glActiveTexture = Bind <ActiveTexture>("glActiveTexture"); glTexImage2D = Bind <TexImage2D>("glTexImage2D"); glTexParameteri = Bind <TexParameteri>("glTexParameteri"); glTexParameterf = Bind <TexParameterf>("glTexParameterf"); if (Profile != GLProfile.Legacy) { if (Profile != GLProfile.Embedded) { glGetTexImage = Bind <GetTexImage>("glGetTexImage"); glBindFragDataLocation = Bind <BindFragDataLocation>("glBindFragDataLocation"); } else { glGetTexImage = null; glBindFragDataLocation = null; } glGenVertexArrays = Bind <GenVertexArrays>("glGenVertexArrays"); glBindVertexArray = Bind <BindVertexArray>("glBindVertexArray"); glGenFramebuffers = Bind <GenFramebuffers>("glGenFramebuffers"); glBindFramebuffer = Bind <BindFramebuffer>("glBindFramebuffer"); glFramebufferTexture2D = Bind <FramebufferTexture2D>("glFramebufferTexture2D"); glDeleteFramebuffers = Bind <DeleteFramebuffers>("glDeleteFramebuffers"); glGenRenderbuffers = Bind <GenRenderbuffers>("glGenRenderbuffers"); glBindRenderbuffer = Bind <BindRenderbuffer>("glBindRenderbuffer"); glRenderbufferStorage = Bind <RenderbufferStorage>("glRenderbufferStorage"); glDeleteRenderbuffers = Bind <DeleteRenderbuffers>("glDeleteRenderbuffers"); glFramebufferRenderbuffer = Bind <FramebufferRenderbuffer>("glFramebufferRenderbuffer"); glCheckFramebufferStatus = Bind <CheckFramebufferStatus>("glCheckFramebufferStatus"); } else { glGenVertexArrays = null; glBindVertexArray = null; glBindFragDataLocation = null; glGenFramebuffers = Bind <GenFramebuffers>("glGenFramebuffersEXT"); glBindFramebuffer = Bind <BindFramebuffer>("glBindFramebufferEXT"); glFramebufferTexture2D = Bind <FramebufferTexture2D>("glFramebufferTexture2DEXT"); glDeleteFramebuffers = Bind <DeleteFramebuffers>("glDeleteFramebuffersEXT"); glGenRenderbuffers = Bind <GenRenderbuffers>("glGenRenderbuffersEXT"); glBindRenderbuffer = Bind <BindRenderbuffer>("glBindRenderbufferEXT"); glRenderbufferStorage = Bind <RenderbufferStorage>("glRenderbufferStorageEXT"); glDeleteRenderbuffers = Bind <DeleteRenderbuffers>("glDeleteRenderbuffersEXT"); glFramebufferRenderbuffer = Bind <FramebufferRenderbuffer>("glFramebufferRenderbufferEXT"); glCheckFramebufferStatus = Bind <CheckFramebufferStatus>("glCheckFramebufferStatusEXT"); } } catch (Exception e) { WriteGraphicsLog("Failed to initialize OpenGL bindings.\nInner exception was: {0}".F(e)); throw new InvalidProgramException("Failed to initialize OpenGL. See graphics.log for details.", e); } }
public static void Initialize() { try { // First set up the bindings we need for error handling glEnable = Bind <Enable>("glEnable"); glDisable = Bind <Disable>("glDisable"); glGetError = Bind <GetError>("glGetError"); glGetStringInternal = Bind <GetString>("glGetString"); glGetStringiInternal = Bind <GetStringi>("glGetStringi"); } catch (Exception e) { throw new InvalidProgramException("Failed to initialize low-level OpenGL bindings. GPU information is not available.", e); } DetectGLFeatures(); if (!Features.HasFlag(GLFeatures.Core)) { WriteGraphicsLog("Unsupported OpenGL version: " + glGetString(GL_VERSION)); throw new InvalidProgramException("OpenGL Version Error: See graphics.log for details."); } // Setup the debug message callback handler if (Features.HasFlag(GLFeatures.DebugMessagesCallback)) { try { glDebugMessageCallback = Bind <DebugMessageCallback>("glDebugMessageCallback"); glDebugMessageInsert = Bind <DebugMessageInsert>("glDebugMessageInsert"); glEnable(GL_DEBUG_OUTPUT); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); // Need to keep a reference to the callback so it doesn't get garbage collected DebugMessageHandle = DebugMessageHandler; glDebugMessageCallback(DebugMessageHandle, IntPtr.Zero); } catch (Exception e) { throw new InvalidProgramException("Failed to initialize an OpenGL debug message callback.", e); } } Console.WriteLine("OpenGL version: " + glGetString(GL_VERSION)); try { glFlush = Bind <Flush>("glFlush"); glViewport = Bind <Viewport>("glViewport"); glClear = Bind <Clear>("glClear"); glClearColor = Bind <ClearColor>("glClearColor"); glGetIntegerv = Bind <GetIntegerv>("glGetIntegerv"); glFinish = Bind <Finish>("glFinish"); glCreateProgram = Bind <CreateProgram>("glCreateProgram"); glUseProgram = Bind <UseProgram>("glUseProgram"); glGetProgramiv = Bind <GetProgramiv>("glGetProgramiv"); glCreateShader = Bind <CreateShader>("glCreateShader"); glShaderSource = Bind <ShaderSource>("glShaderSource"); glCompileShader = Bind <CompileShader>("glCompileShader"); glGetShaderiv = Bind <GetShaderiv>("glGetShaderiv"); glAttachShader = Bind <AttachShader>("glAttachShader"); glGetShaderInfoLog = Bind <GetShaderInfoLog>("glGetShaderInfoLog"); glLinkProgram = Bind <LinkProgram>("glLinkProgram"); glGetProgramInfoLog = Bind <GetProgramInfoLog>("glGetProgramInfoLog"); glGetUniformLocation = Bind <GetUniformLocation>("glGetUniformLocation"); glGetActiveUniform = Bind <GetActiveUniform>("glGetActiveUniform"); glUniform1i = Bind <Uniform1i>("glUniform1i"); glUniform1f = Bind <Uniform1f>("glUniform1f"); glUniform2f = Bind <Uniform2f>("glUniform2f"); glUniform3f = Bind <Uniform3f>("glUniform3f"); glUniform1fv = Bind <Uniform1fv>("glUniform1fv"); glUniform2fv = Bind <Uniform2fv>("glUniform2fv"); glUniform3fv = Bind <Uniform3fv>("glUniform3fv"); glUniform4fv = Bind <Uniform4fv>("glUniform4fv"); glUniformMatrix4fv = Bind <UniformMatrix4fv>("glUniformMatrix4fv"); glGenBuffers = Bind <GenBuffers>("glGenBuffers"); glBindBuffer = Bind <BindBuffer>("glBindBuffer"); glBufferData = Bind <BufferData>("glBufferData"); glBufferSubData = Bind <BufferSubData>("glBufferSubData"); glDeleteBuffers = Bind <DeleteBuffers>("glDeleteBuffers"); glGenVertexArrays = Bind <GenVertexArrays>("glGenVertexArrays"); glBindVertexArray = Bind <BindVertexArray>("glBindVertexArray"); glBindAttribLocation = Bind <BindAttribLocation>("glBindAttribLocation"); glBindFragDataLocation = Bind <BindFragDataLocation>("glBindFragDataLocation"); glVertexAttribPointer = Bind <VertexAttribPointer>("glVertexAttribPointer"); glEnableVertexAttribArray = Bind <EnableVertexAttribArray>("glEnableVertexAttribArray"); glDisableVertexAttribArray = Bind <DisableVertexAttribArray>("glDisableVertexAttribArray"); glDrawArrays = Bind <DrawArrays>("glDrawArrays"); glBlendEquation = Bind <BlendEquation>("glBlendEquation"); glBlendEquationSeparate = Bind <BlendEquationSeparate>("glBlendEquationSeparate"); glBlendFunc = Bind <BlendFunc>("glBlendFunc"); glDepthFunc = Bind <DepthFunc>("glDepthFunc"); glScissor = Bind <Scissor>("glScissor"); glReadPixels = Bind <ReadPixels>("glReadPixels"); glGenTextures = Bind <GenTextures>("glGenTextures"); glDeleteTextures = Bind <DeleteTextures>("glDeleteTextures"); glIsTexture = Bind <IsTexture>("glIsTexture"); glBindTexture = Bind <BindTexture>("glBindTexture"); glActiveTexture = Bind <ActiveTexture>("glActiveTexture"); glTexImage2D = Bind <TexImage2D>("glTexImage2D"); glGetTexImage = Bind <GetTexImage>("glGetTexImage"); glTexParameteri = Bind <TexParameteri>("glTexParameteri"); glTexParameterf = Bind <TexParameterf>("glTexParameterf"); glGenFramebuffers = Bind <GenFramebuffers>("glGenFramebuffers"); glBindFramebuffer = Bind <BindFramebuffer>("glBindFramebuffer"); glFramebufferTexture2D = Bind <FramebufferTexture2D>("glFramebufferTexture2D"); glDeleteFramebuffers = Bind <DeleteFramebuffers>("glDeleteFramebuffers"); glGenRenderbuffers = Bind <GenRenderbuffers>("glGenRenderbuffers"); glBindRenderbuffer = Bind <BindRenderbuffer>("glBindRenderbuffer"); glRenderbufferStorage = Bind <RenderbufferStorage>("glRenderbufferStorage"); glDeleteRenderbuffers = Bind <DeleteRenderbuffers>("glDeleteRenderbuffers"); glFramebufferRenderbuffer = Bind <FramebufferRenderbuffer>("glFramebufferRenderbuffer"); glCheckFramebufferStatus = Bind <CheckFramebufferStatus>("glCheckFramebufferStatus"); } catch (Exception e) { WriteGraphicsLog("Failed to initialize OpenGL bindings.\nInner exception was: {0}".F(e)); throw new InvalidProgramException("Failed to initialize OpenGL. See graphics.log for details.", e); } }
/* END STRING MARKER FUNCTIONS */ #endif private void LoadGLEntryPoints() { string baseErrorString; if (useES2) { baseErrorString = "OpenGL ES 2.0"; } else { baseErrorString = "OpenGL 2.1"; } baseErrorString += " support is required!"; /* Basic entry points. If you don't have these, you're screwed. */ try { INTERNAL_glGetString = (GetString) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGetString"), typeof(GetString) ); glGetIntegerv = (GetIntegerv) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGetIntegerv"), typeof(GetIntegerv) ); glEnable = (Enable) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glEnable"), typeof(Enable) ); glDisable = (Disable) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDisable"), typeof(Disable) ); glViewport = (G_Viewport) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glViewport"), typeof(G_Viewport) ); glScissor = (Scissor) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glScissor"), typeof(Scissor) ); glBlendColor = (BlendColor) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glBlendColor"), typeof(BlendColor) ); glBlendFuncSeparate = (BlendFuncSeparate) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glBlendFuncSeparate"), typeof(BlendFuncSeparate) ); glBlendEquationSeparate = (BlendEquationSeparate) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glBlendEquationSeparate"), typeof(BlendEquationSeparate) ); glColorMask = (ColorMask) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glColorMask"), typeof(ColorMask) ); glDepthMask = (DepthMask) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDepthMask"), typeof(DepthMask) ); glDepthFunc = (DepthFunc) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDepthFunc"), typeof(DepthFunc) ); glStencilMask = (StencilMask) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glStencilMask"), typeof(StencilMask) ); glStencilFuncSeparate = (StencilFuncSeparate) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glStencilFuncSeparate"), typeof(StencilFuncSeparate) ); glStencilOpSeparate = (StencilOpSeparate) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glStencilOpSeparate"), typeof(StencilOpSeparate) ); glStencilFunc = (StencilFunc) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glStencilFunc"), typeof(StencilFunc) ); glStencilOp = (StencilOp) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glStencilOp"), typeof(StencilOp) ); glFrontFace = (FrontFace) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glFrontFace"), typeof(FrontFace) ); glPolygonOffset = (PolygonOffset) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glPolygonOffset"), typeof(PolygonOffset) ); glGenTextures = (GenTextures) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGenTextures"), typeof(GenTextures) ); glDeleteTextures = (DeleteTextures) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDeleteTextures"), typeof(DeleteTextures) ); glBindTexture = (G_BindTexture) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glBindTexture"), typeof(G_BindTexture) ); glTexImage2D = (TexImage2D) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glTexImage2D"), typeof(TexImage2D) ); glTexSubImage2D = (TexSubImage2D) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glTexSubImage2D"), typeof(TexSubImage2D) ); glCompressedTexImage2D = (CompressedTexImage2D) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glCompressedTexImage2D"), typeof(CompressedTexImage2D) ); glCompressedTexSubImage2D = (CompressedTexSubImage2D) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glCompressedTexSubImage2D"), typeof(CompressedTexSubImage2D) ); glTexParameteri = (TexParameteri) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glTexParameteri"), typeof(TexParameteri) ); glTexParameterf = (TexParameterf) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glTexParameterf"), typeof(TexParameterf) ); glActiveTexture = (ActiveTexture) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glActiveTexture"), typeof(ActiveTexture) ); glPixelStorei = (PixelStorei) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glPixelStorei"), typeof(PixelStorei) ); glGenBuffers = (GenBuffers) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGenBuffers"), typeof(GenBuffers) ); glDeleteBuffers = (DeleteBuffers) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDeleteBuffers"), typeof(DeleteBuffers) ); glBindBuffer = (BindBuffer) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glBindBuffer"), typeof(BindBuffer) ); glBufferData = (BufferData) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glBufferData"), typeof(BufferData) ); glBufferSubData = (BufferSubData) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glBufferSubData"), typeof(BufferSubData) ); glClearColor = (ClearColor) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glClearColor"), typeof(ClearColor) ); glClearStencil = (ClearStencil) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glClearStencil"), typeof(ClearStencil) ); glClear = (G_Clear) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glClear"), typeof(G_Clear) ); glDrawBuffers = (DrawBuffers) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDrawBuffers"), typeof(DrawBuffers) ); glReadPixels = (ReadPixels) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glReadPixels"), typeof(ReadPixels) ); glVertexAttribPointer = (VertexAttribPointer) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glVertexAttribPointer"), typeof(VertexAttribPointer) ); glEnableVertexAttribArray = (EnableVertexAttribArray) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glEnableVertexAttribArray"), typeof(EnableVertexAttribArray) ); glDisableVertexAttribArray = (DisableVertexAttribArray) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDisableVertexAttribArray"), typeof(DisableVertexAttribArray) ); glDrawArrays = (DrawArrays) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDrawArrays"), typeof(DrawArrays) ); } catch { throw new NoSuitableGraphicsDeviceException(baseErrorString); } /* ARB_draw_elements_base_vertex is ideal! */ IntPtr ep = SDL.SDL_GL_GetProcAddress("glDrawRangeElementsBaseVertex"); supportsBaseVertex = ep != IntPtr.Zero; if (supportsBaseVertex) { glDrawRangeElementsBaseVertex = (DrawRangeElementsBaseVertex) Marshal.GetDelegateForFunctionPointer( ep, typeof(DrawRangeElementsBaseVertex) ); glDrawRangeElements = (DrawRangeElements) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDrawRangeElements"), typeof(DrawRangeElements) ); } else { /* DrawRangeElements is better, but some ES2 targets don't have it. */ ep = SDL.SDL_GL_GetProcAddress("glDrawRangeElements"); if (ep != IntPtr.Zero) { glDrawRangeElements = (DrawRangeElements) Marshal.GetDelegateForFunctionPointer( ep, typeof(DrawRangeElements) ); glDrawRangeElementsBaseVertex = DrawRangeElementsNoBase; } else { ep = SDL.SDL_GL_GetProcAddress("glDrawElements"); if (ep == IntPtr.Zero) { throw new NoSuitableGraphicsDeviceException(baseErrorString); } glDrawElements = (DrawElements) Marshal.GetDelegateForFunctionPointer( ep, typeof(DrawElements) ); glDrawRangeElements = DrawRangeElementsUnchecked; glDrawRangeElementsBaseVertex = DrawRangeElementsNoBaseUnchecked; } } /* These functions are NOT supported in ES. * NVIDIA or desktop ES might, but real scenarios where you need ES * will certainly not have these. * -flibit */ if (useES2) { ep = SDL.SDL_GL_GetProcAddress("glPolygonMode"); if (ep != IntPtr.Zero) { glPolygonMode = (PolygonMode) Marshal.GetDelegateForFunctionPointer( ep, typeof(PolygonMode) ); } else { glPolygonMode = PolygonModeESError; } ep = SDL.SDL_GL_GetProcAddress("glGetTexImage"); if (ep != IntPtr.Zero) { glGetTexImage = (GetTexImage) Marshal.GetDelegateForFunctionPointer( ep, typeof(GetTexImage) ); } else { glGetTexImage = GetTexImageESError; } ep = SDL.SDL_GL_GetProcAddress("glGetBufferSubData"); if (ep != IntPtr.Zero) { glGetBufferSubData = (GetBufferSubData) Marshal.GetDelegateForFunctionPointer( ep, typeof(GetBufferSubData) ); } else { glGetBufferSubData = GetBufferSubDataESError; } } else { try { glPolygonMode = (PolygonMode) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glPolygonMode"), typeof(PolygonMode) ); glGetTexImage = (GetTexImage) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGetTexImage"), typeof(GetTexImage) ); glGetBufferSubData = (GetBufferSubData) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGetBufferSubData"), typeof(GetBufferSubData) ); } catch { throw new NoSuitableGraphicsDeviceException(baseErrorString); } } /* We need _some_ form of depth range, ES... */ IntPtr drPtr = SDL.SDL_GL_GetProcAddress("glDepthRange"); if (drPtr != IntPtr.Zero) { glDepthRange = (DepthRange) Marshal.GetDelegateForFunctionPointer( drPtr, typeof(DepthRange) ); } else { drPtr = SDL.SDL_GL_GetProcAddress("glDepthRangef"); if (drPtr == IntPtr.Zero) { throw new NoSuitableGraphicsDeviceException(baseErrorString); } glDepthRangef = (DepthRangef) Marshal.GetDelegateForFunctionPointer( drPtr, typeof(DepthRangef) ); glDepthRange = DepthRangeFloat; } drPtr = SDL.SDL_GL_GetProcAddress("glClearDepth"); if (drPtr != IntPtr.Zero) { glClearDepth = (ClearDepth) Marshal.GetDelegateForFunctionPointer( drPtr, typeof(ClearDepth) ); } else { drPtr = SDL.SDL_GL_GetProcAddress("glClearDepthf"); if (drPtr == IntPtr.Zero) { throw new NoSuitableGraphicsDeviceException(baseErrorString); } glClearDepthf = (ClearDepthf) Marshal.GetDelegateForFunctionPointer( drPtr, typeof(ClearDepthf) ); glClearDepth = ClearDepthFloat; } /* Silently fail if using GLES. You didn't need these, right...? >_> */ try { glTexImage3D = (TexImage3D) Marshal.GetDelegateForFunctionPointer( TryGetEPEXT("glTexImage3D", "OES"), typeof(TexImage3D) ); glTexSubImage3D = (TexSubImage3D) Marshal.GetDelegateForFunctionPointer( TryGetEPEXT("glTexSubImage3D", "OES"), typeof(TexSubImage3D) ); glGenQueries = (GenQueries) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGenQueries"), typeof(GenQueries) ); glDeleteQueries = (DeleteQueries) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDeleteQueries"), typeof(DeleteQueries) ); glBeginQuery = (BeginQuery) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glBeginQuery"), typeof(BeginQuery) ); glEndQuery = (EndQuery) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glEndQuery"), typeof(EndQuery) ); glGetQueryObjectuiv = (GetQueryObjectuiv) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGetQueryObjectuiv"), typeof(GetQueryObjectuiv) ); } catch { if (useES2) { FNAPlatform.Log("Some non-ES functions failed to load. Beware..."); } else { throw new NoSuitableGraphicsDeviceException(baseErrorString); } } /* ARB_framebuffer_object. We're flexible, but not _that_ flexible. */ try { glGenFramebuffers = (GenFramebuffers) Marshal.GetDelegateForFunctionPointer( TryGetEPEXT("glGenFramebuffers"), typeof(GenFramebuffers) ); glDeleteFramebuffers = (DeleteFramebuffers) Marshal.GetDelegateForFunctionPointer( TryGetEPEXT("glDeleteFramebuffers"), typeof(DeleteFramebuffers) ); glBindFramebuffer = (G_BindFramebuffer) Marshal.GetDelegateForFunctionPointer( TryGetEPEXT("glBindFramebuffer"), typeof(G_BindFramebuffer) ); glFramebufferTexture2D = (FramebufferTexture2D) Marshal.GetDelegateForFunctionPointer( TryGetEPEXT("glFramebufferTexture2D"), typeof(FramebufferTexture2D) ); glFramebufferRenderbuffer = (FramebufferRenderbuffer) Marshal.GetDelegateForFunctionPointer( TryGetEPEXT("glFramebufferRenderbuffer"), typeof(FramebufferRenderbuffer) ); glGenerateMipmap = (GenerateMipmap) Marshal.GetDelegateForFunctionPointer( TryGetEPEXT("glGenerateMipmap"), typeof(GenerateMipmap) ); glGenRenderbuffers = (GenRenderbuffers) Marshal.GetDelegateForFunctionPointer( TryGetEPEXT("glGenRenderbuffers"), typeof(GenRenderbuffers) ); glDeleteRenderbuffers = (DeleteRenderbuffers) Marshal.GetDelegateForFunctionPointer( TryGetEPEXT("glDeleteRenderbuffers"), typeof(DeleteRenderbuffers) ); glBindRenderbuffer = (BindRenderbuffer) Marshal.GetDelegateForFunctionPointer( TryGetEPEXT("glBindRenderbuffer"), typeof(BindRenderbuffer) ); glRenderbufferStorage = (RenderbufferStorage) Marshal.GetDelegateForFunctionPointer( TryGetEPEXT("glRenderbufferStorage"), typeof(RenderbufferStorage) ); } catch { throw new NoSuitableGraphicsDeviceException("OpenGL framebuffer support is required!"); } /* EXT_framebuffer_blit (or ARB_framebuffer_object) is needed by the faux-backbuffer. */ supportsFauxBackbuffer = true; try { glBlitFramebuffer = (BlitFramebuffer) Marshal.GetDelegateForFunctionPointer( TryGetEPEXT("glBlitFramebuffer"), typeof(BlitFramebuffer) ); } catch { supportsFauxBackbuffer = false; } /* ARB_instanced_arrays/ARB_draw_instanced are almost optional. */ SupportsHardwareInstancing = true; try { glVertexAttribDivisor = (VertexAttribDivisor) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glVertexAttribDivisor"), typeof(VertexAttribDivisor) ); /* The likelihood of someone having BaseVertex but not Instanced is 0...? */ if (supportsBaseVertex) { glDrawElementsInstancedBaseVertex = (DrawElementsInstancedBaseVertex) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDrawElementsInstancedBaseVertex"), typeof(DrawElementsInstancedBaseVertex) ); } else { glDrawElementsInstanced = (DrawElementsInstanced) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDrawElementsInstanced"), typeof(DrawElementsInstanced) ); glDrawElementsInstancedBaseVertex = DrawElementsInstancedNoBase; } } catch { SupportsHardwareInstancing = false; } /* EXT_draw_buffers2 is probably used by nobody. */ try { glColorMaskIndexedEXT = (ColorMaskIndexedEXT) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glColorMaskIndexedEXT"), typeof(ColorMaskIndexedEXT) ); } catch { // FIXME: SupportsIndependentWriteMasks? -flibit } /* EXT_framebuffer_multisample/ARB_texture_multisample is glitter -flibit */ supportsMultisampling = true; try { glRenderbufferStorageMultisample = (RenderbufferStorageMultisample) Marshal.GetDelegateForFunctionPointer( TryGetEPEXT("glRenderbufferStorageMultisample"), typeof(RenderbufferStorageMultisample) ); glSampleMaski = (SampleMaski) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glSampleMaski"), typeof(SampleMaski) ); } catch { supportsMultisampling = false; } if (useCoreProfile) { try { INTERNAL_glGetStringi = (GetStringi) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGetStringi"), typeof(GetStringi) ); glGenVertexArrays = (GenVertexArrays) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGenVertexArrays"), typeof(GenVertexArrays) ); glDeleteVertexArrays = (DeleteVertexArrays) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDeleteVertexArrays"), typeof(DeleteVertexArrays) ); glBindVertexArray = (BindVertexArray) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glBindVertexArray"), typeof(BindVertexArray) ); } catch { throw new NoSuitableGraphicsDeviceException("OpenGL 3.2 support is required!"); } } #if DEBUG /* ARB_debug_output, for debug contexts */ IntPtr messageCallback = SDL.SDL_GL_GetProcAddress("glDebugMessageCallbackARB"); IntPtr messageControl = SDL.SDL_GL_GetProcAddress("glDebugMessageControlARB"); if (messageCallback == IntPtr.Zero || messageControl == IntPtr.Zero) { FNAPlatform.Log("ARB_debug_output not supported!"); } else { glDebugMessageCallbackARB = (DebugMessageCallback) Marshal.GetDelegateForFunctionPointer( messageCallback, typeof(DebugMessageCallback) ); glDebugMessageControlARB = (DebugMessageControl) Marshal.GetDelegateForFunctionPointer( messageControl, typeof(DebugMessageControl) ); glDebugMessageControlARB( GLenum.GL_DONT_CARE, GLenum.GL_DONT_CARE, GLenum.GL_DONT_CARE, 0, IntPtr.Zero, true ); glDebugMessageControlARB( GLenum.GL_DONT_CARE, GLenum.GL_DEBUG_TYPE_OTHER_ARB, GLenum.GL_DEBUG_SEVERITY_LOW_ARB, 0, IntPtr.Zero, false ); glDebugMessageControlARB( GLenum.GL_DONT_CARE, GLenum.GL_DEBUG_TYPE_OTHER_ARB, GLenum.GL_DEBUG_SEVERITY_NOTIFICATION_ARB, 0, IntPtr.Zero, false ); glDebugMessageCallbackARB(DebugCall, IntPtr.Zero); } /* GREMEDY_string_marker, for apitrace */ IntPtr stringMarkerCallback = SDL.SDL_GL_GetProcAddress("glStringMarkerGREMEDY"); if (stringMarkerCallback == IntPtr.Zero) { FNAPlatform.Log("GREMEDY_string_marker not supported!"); } else { glStringMarkerGREMEDY = (StringMarkerGREMEDY) Marshal.GetDelegateForFunctionPointer( stringMarkerCallback, typeof(StringMarkerGREMEDY) ); } #endif }
public static void InitGL_3_0(OpenGLContext ctx) { glColorMaski = ctx.GetProc<ColorMaski>("glColorMaski"); glGetBooleani_v = ctx.GetProc<GetBooleani_v>("glGetBooleani_v"); glGetIntegeri_v = ctx.GetProc<GetIntegeri_v>("glGetIntegeri_v"); glEnablei = ctx.GetProc<Enablei>("glEnablei"); glDisablei = ctx.GetProc<Disablei>("glDisablei"); glIsEnabledi = ctx.GetProc<IsEnabledi>("glIsEnabledi"); glBeginTransformFeedback = ctx.GetProc<BeginTransformFeedback>("glBeginTransformFeedback"); glEndTransformFeedback = ctx.GetProc<EndTransformFeedback>("glEndTransformFeedback"); glBindBufferRange = ctx.GetProc<BindBufferRange>("glBindBufferRange"); glBindBufferBase = ctx.GetProc<BindBufferBase>("glBindBufferBase"); glTransformFeedbackVaryings = ctx.GetProc<TransformFeedbackVaryings>("glTransformFeedbackVaryings"); glGetTransformFeedbackVarying = ctx.GetProc<GetTransformFeedbackVarying>("glGetTransformFeedbackVarying"); glClampColor = ctx.GetProc<ClampColor>("glClampColor"); glBeginConditionalRender = ctx.GetProc<BeginConditionalRender>("glBeginConditionalRender"); glEndConditionalRender = ctx.GetProc<EndConditionalRender>("glEndConditionalRender"); glVertexAttribIPointer = ctx.GetProc<VertexAttribIPointer>("glVertexAttribIPointer"); glGetVertexAttribIiv = ctx.GetProc<GetVertexAttribIiv>("glGetVertexAttribIiv"); glGetVertexAttribIuiv = ctx.GetProc<GetVertexAttribIuiv>("glGetVertexAttribIuiv"); glVertexAttribI1i = ctx.GetProc<VertexAttribI1i>("glVertexAttribI1i"); glVertexAttribI2i = ctx.GetProc<VertexAttribI2i>("glVertexAttribI2i"); glVertexAttribI3i = ctx.GetProc<VertexAttribI3i>("glVertexAttribI3i"); glVertexAttribI4i = ctx.GetProc<VertexAttribI4i>("glVertexAttribI4i"); glVertexAttribI1ui = ctx.GetProc<VertexAttribI1ui>("glVertexAttribI1ui"); glVertexAttribI2ui = ctx.GetProc<VertexAttribI2ui>("glVertexAttribI2ui"); glVertexAttribI3ui = ctx.GetProc<VertexAttribI3ui>("glVertexAttribI3ui"); glVertexAttribI4ui = ctx.GetProc<VertexAttribI4ui>("glVertexAttribI4ui"); glVertexAttribI1iv = ctx.GetProc<VertexAttribI1iv>("glVertexAttribI1iv"); glVertexAttribI2iv = ctx.GetProc<VertexAttribI2iv>("glVertexAttribI2iv"); glVertexAttribI3iv = ctx.GetProc<VertexAttribI3iv>("glVertexAttribI3iv"); glVertexAttribI4iv = ctx.GetProc<VertexAttribI4iv>("glVertexAttribI4iv"); glVertexAttribI1uiv = ctx.GetProc<VertexAttribI1uiv>("glVertexAttribI1uiv"); glVertexAttribI2uiv = ctx.GetProc<VertexAttribI2uiv>("glVertexAttribI2uiv"); glVertexAttribI3uiv = ctx.GetProc<VertexAttribI3uiv>("glVertexAttribI3uiv"); glVertexAttribI4uiv = ctx.GetProc<VertexAttribI4uiv>("glVertexAttribI4uiv"); glVertexAttribI4bv = ctx.GetProc<VertexAttribI4bv>("glVertexAttribI4bv"); glVertexAttribI4sv = ctx.GetProc<VertexAttribI4sv>("glVertexAttribI4sv"); glVertexAttribI4ubv = ctx.GetProc<VertexAttribI4ubv>("glVertexAttribI4ubv"); glVertexAttribI4usv = ctx.GetProc<VertexAttribI4usv>("glVertexAttribI4usv"); glGetUniformuiv = ctx.GetProc<GetUniformuiv>("glGetUniformuiv"); glBindFragDataLocation = ctx.GetProc<BindFragDataLocation>("glBindFragDataLocation"); glGetFragDataLocation = ctx.GetProc<GetFragDataLocation>("glGetFragDataLocation"); glUniform1ui = ctx.GetProc<Uniform1ui>("glUniform1ui"); glUniform2ui = ctx.GetProc<Uniform2ui>("glUniform2ui"); glUniform3ui = ctx.GetProc<Uniform3ui>("glUniform3ui"); glUniform4ui = ctx.GetProc<Uniform4ui>("glUniform4ui"); glUniform1uiv = ctx.GetProc<Uniform1uiv>("glUniform1uiv"); glUniform2uiv = ctx.GetProc<Uniform2uiv>("glUniform2uiv"); glUniform3uiv = ctx.GetProc<Uniform3uiv>("glUniform3uiv"); glUniform4uiv = ctx.GetProc<Uniform4uiv>("glUniform4uiv"); glTexParameterIiv = ctx.GetProc<TexParameterIiv>("glTexParameterIiv"); glTexParameterIuiv = ctx.GetProc<TexParameterIuiv>("glTexParameterIuiv"); glGetTexParameterIiv = ctx.GetProc<GetTexParameterIiv>("glGetTexParameterIiv"); glGetTexParameterIuiv = ctx.GetProc<GetTexParameterIuiv>("glGetTexParameterIuiv"); glClearBufferiv = ctx.GetProc<ClearBufferiv>("glClearBufferiv"); glClearBufferuiv = ctx.GetProc<ClearBufferuiv>("glClearBufferuiv"); glClearBufferfv = ctx.GetProc<ClearBufferfv>("glClearBufferfv"); glClearBufferfi = ctx.GetProc<ClearBufferfi>("glClearBufferfi"); glGetStringi = ctx.GetProc<GetStringi>("glGetStringi"); }