/// <summary>TODO</summary> protected override void RenderMap(Graphics g) { if (g == null) { throw new ArgumentNullException("g"); } using (var brush = new SolidBrush(this.BackColor)) g.FillRectangle(brush, ClientRectangle); g.ScaleTransform(1.0f / MapScale, 1.0f / MapScale); MapBuffer.Render(g, Point.Empty, ClientSize); }
/// <summary>TODO</summary> /// <param name="delta"></param> /// <returns>Clipping rectangle requiring re-painting.</returns> protected virtual Rectangle VerticalScrollBufferedGraphics(int delta) { if (delta == 0) { return(Rectangle.Empty); } // Render(MapBuffer, MapSpare.Graphics, new Point(0,-delta)); MapBuffer.Render(MapSpare.Graphics, new Point(0, -delta), ClientSize); var temp = MapBuffer; MapBuffer = MapSpare; MapSpare = temp; if (delta < 0) { return(new Rectangle(0, 0, ClientSize.Width, -delta)); } else { return(new Rectangle(0, ClientSize.Height - delta, ClientSize.Width, delta)); } }
/// <summary>TODO</summary> void ResizeBuffer() { var rectangle = new Rectangle(Point.Empty, ClientSize); if (ClientSize != _bufferedGraphicsContext.MaximumBuffer) { _bufferedGraphicsContext.MaximumBuffer = ClientSize; if (MapBuffer != null) { MapBuffer.Dispose(); } MapBuffer = _bufferedGraphicsContext.Allocate(this.CreateGraphics(), rectangle); if (MapSpare != null) { MapSpare.Dispose(); } MapSpare = _bufferedGraphicsContext.Allocate(this.CreateGraphics(), rectangle); } PaintBuffer(rectangle); }
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 }
private bool NewZonePlacementCallback(bool cancelled, Point location, object arg) { NewZoneData zoneData = (NewZoneData)arg; if (!cancelled) { // Check to see if the new zone overlaps any existing tiles for (int z = 0; z < zoneData.TilesHeight; z++) { int dz = z + gridOffset.z + location.Y; for (int x = 0; x < zoneData.TilesWidth; x++) { int dx = x + gridOffset.x + location.X; CoordXZ tileCoord = new CoordXZ(dx, dz, WorldMap.tileSize); MapTile tile = worldMap.GetTile(tileCoord); if (tile != null) { // overlaps existing tiles return(false); } } } MapZone zone = worldMap.CreateZone(zoneData.ZoneName); int samplesPerTile = WorldMap.metersPerTile / zoneData.MetersPerSample; ValueMapLayer heightFieldLayer = worldMap.HeightFieldLayer as ValueMapLayer; for (int z = 0; z < zoneData.TilesHeight; z++) { int dz = z + gridOffset.z + location.Y; for (int x = 0; x < zoneData.TilesWidth; x++) { int dx = x + gridOffset.x + location.X; CoordXZ tileCoord = new CoordXZ(dx, dz, WorldMap.tileSize); MapBuffer tileHeightmap = heightFieldLayer.CreateCompatibleMapBuffer(zoneData.Heightmap, zoneData.MetersPerSample, x * samplesPerTile, z * samplesPerTile, samplesPerTile, zoneData.MinHeight, zoneData.MaxHeight); MapTile tile = worldMap.CreateTile(tileCoord); tile.Zone = zone; if (tileHeightmap.MetersPerSample != heightFieldLayer.MetersPerSample) { tileHeightmap = tileHeightmap.Scale(worldMap.MetersPerTile / heightFieldLayer.MetersPerSample); } heightFieldLayer.CopyIn(tileCoord, tileHeightmap); ImageGridCell cell = imageGrid.CreateCell(x + location.X, z + location.Y); cell.Image = currentViewLayer.CreateThumbnail(tileCoord, worldMap.TileSize, imageGrid.CellSize); } } AddZone(zone); } return(true); }
/* END STRING MARKER FUNCTIONS */ #endif 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) ); 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. * While we do not directly call glVertexAttribDivisor ourselves, * we still need to check for ARB_instanced_arrays support. * -flibit */ SupportsHardwareInstancing = SDL.SDL_GL_GetProcAddress("glVertexAttribDivisor") != IntPtr.Zero; try { 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 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 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) ); glGetTexLevelParameteriv = (GetTexLevelParameteriv) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGetTexLevelParameteriv"), typeof(GetTexLevelParameteriv) ); 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) ); glEnableVertexAttribArray = (EnableVertexAttribArray) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glEnableVertexAttribArray"), typeof(EnableVertexAttribArray) ); glDisableVertexAttribArray = (DisableVertexAttribArray) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDisableVertexAttribArray"), typeof(DisableVertexAttribArray) ); glVertexAttribPointer = (G_VertexAttribPointer) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glVertexAttribPointer"), typeof(G_VertexAttribPointer) ); 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) ); 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) ); glCreateShader = (CreateShader) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glCreateShader"), typeof(CreateShader) ); glDeleteShader = (DeleteShader) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDeleteShader"), typeof(DeleteShader) ); glShaderSource = (ShaderSource) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glShaderSource"), typeof(ShaderSource) ); glCompileShader = (CompileShader) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glCompileShader"), typeof(CompileShader) ); glCreateProgram = (CreateProgram) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glCreateProgram"), typeof(CreateProgram) ); glDeleteProgram = (DeleteProgram) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDeleteProgram"), typeof(DeleteProgram) ); glAttachShader = (AttachShader) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glAttachShader"), typeof(AttachShader) ); glDetachShader = (DetachShader) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glDetachShader"), typeof(DetachShader) ); glLinkProgram = (LinkProgram) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glLinkProgram"), typeof(LinkProgram) ); glUseProgram = (UseProgram) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glUseProgram"), typeof(UseProgram) ); glUniform1i = (Uniform1i) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glUniform1i"), typeof(Uniform1i) ); glUniform4fv = (Uniform4fv) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glUniform4fv"), typeof(Uniform4fv) ); glGetShaderiv = (GetShaderiv) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGetShaderiv"), typeof(GetShaderiv) ); glGetProgramiv = (GetProgramiv) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGetProgramiv"), typeof(GetProgramiv) ); glGetUniformLocation = (GetUniformLocation) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGetUniformLocation"), typeof(GetUniformLocation) ); glGetAttribLocation = (GetAttribLocation) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGetAttribLocation"), typeof(GetAttribLocation) ); glBindAttribLocation = (BindAttribLocation) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glBindAttribLocation"), typeof(BindAttribLocation) ); glIsShader = (IsShader) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glIsShader"), typeof(IsShader) ); glIsProgram = (IsProgram) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glIsProgram"), typeof(IsProgram) ); glGetShaderInfoLog = (GetShaderInfoLog) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGetShaderInfoLog"), typeof(GetShaderInfoLog) ); glGetProgramInfoLog = (GetProgramInfoLog) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glGetProgramInfoLog"), typeof(GetProgramInfoLog) ); glFlush = (Flush) Marshal.GetDelegateForFunctionPointer( SDL.SDL_GL_GetProcAddress("glFlush"), typeof(Flush) ); } 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) ); #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; } #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) ); glDebugMessageCallbackARB(DebugCall, IntPtr.Zero); 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 ); } /* 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 InitGL_1_5(OpenGLContext ctx) { glDeleteQueries = ctx.GetProc<DeleteQueries>("glDeleteQueries"); glIsQuery = ctx.GetProc<IsQuery>("glIsQuery"); glBeginQuery = ctx.GetProc<BeginQuery>("glBeginQuery"); glEndQuery = ctx.GetProc<EndQuery>("glEndQuery"); glGetQueryiv = ctx.GetProc<GetQueryiv>("glGetQueryiv"); glGetQueryObjectiv = ctx.GetProc<GetQueryObjectiv>("glGetQueryObjectiv"); glGetQueryObjectuiv = ctx.GetProc<GetQueryObjectuiv>("glGetQueryObjectuiv"); glBindBuffer = ctx.GetProc<BindBuffer>("glBindBuffer"); glDeleteBuffers = ctx.GetProc<DeleteBuffers>("glDeleteBuffers"); glGenBuffers = ctx.GetProc<GenBuffers>("glGenBuffers"); glIsBuffer = ctx.GetProc<IsBuffer>("glIsBuffer"); glBufferData = ctx.GetProc<BufferData>("glBufferData"); glBufferSubData = ctx.GetProc<BufferSubData>("glBufferSubData"); glGetBufferSubData = ctx.GetProc<GetBufferSubData>("glGetBufferSubData"); glMapBuffer = ctx.GetProc<MapBuffer>("glMapBuffer"); glUnmapBuffer = ctx.GetProc<UnmapBuffer>("glUnmapBuffer"); glGetBufferParameteriv = ctx.GetProc<GetBufferParameteriv>("glGetBufferParameteriv"); glGetBufferPointerv = ctx.GetProc<GetBufferPointerv>("glGetBufferPointerv"); }