wgl.odin 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // +build windows
  2. package sys_windows
  3. import "core:c"
  4. foreign import "system:Opengl32.lib"
  5. CONTEXT_MAJOR_VERSION_ARB :: 0x2091
  6. CONTEXT_MINOR_VERSION_ARB :: 0x2092
  7. CONTEXT_FLAGS_ARB :: 0x2094
  8. CONTEXT_PROFILE_MASK_ARB :: 0x9126
  9. CONTEXT_FORWARD_COMPATIBLE_BIT_ARB :: 0x0002
  10. CONTEXT_CORE_PROFILE_BIT_ARB :: 0x00000001
  11. CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB :: 0x00000002
  12. HGLRC :: distinct HANDLE
  13. LPLAYERPLANEDESCRIPTOR :: ^LAYERPLANEDESCRIPTOR
  14. LAYERPLANEDESCRIPTOR :: struct {
  15. nSize: WORD,
  16. nVersion: WORD,
  17. dwFlags: DWORD,
  18. iPixelType: BYTE,
  19. cColorBits: BYTE,
  20. cRedBits: BYTE,
  21. cRedShift: BYTE,
  22. cGreenBits: BYTE,
  23. cGreenShift: BYTE,
  24. cBlueBits: BYTE,
  25. cBlueShift: BYTE,
  26. cAlphaBits: BYTE,
  27. cAlphaShift: BYTE,
  28. cAccumBits: BYTE,
  29. cAccumRedBits: BYTE,
  30. cAccumGreenBits: BYTE,
  31. cAccumBlueBits: BYTE,
  32. cAccumAlphaBits: BYTE,
  33. cDepthBits: BYTE,
  34. cStencilBits: BYTE,
  35. cAuxBuffers: BYTE,
  36. iLayerPlane: BYTE,
  37. bReserved: BYTE,
  38. crTransparent: COLORREF,
  39. }
  40. POINTFLOAT :: struct {x, y: f32}
  41. LPGLYPHMETRICSFLOAT :: ^GLYPHMETRICSFLOAT
  42. GLYPHMETRICSFLOAT :: struct {
  43. gmfBlackBoxX: f32,
  44. gmfBlackBoxY: f32,
  45. gmfptGlyphOrigin: POINTFLOAT,
  46. gmfCellIncX: f32,
  47. gmfCellIncY: f32,
  48. }
  49. CreateContextAttribsARBType :: #type proc "c" (hdc: HDC, hShareContext: rawptr, attribList: [^]c.int) -> HGLRC
  50. ChoosePixelFormatARBType :: #type proc "c" (hdc: HDC, attribIList: [^]c.int, attribFList: [^]f32, maxFormats: DWORD, formats: [^]c.int, numFormats: [^]DWORD) -> BOOL
  51. SwapIntervalEXTType :: #type proc "c" (interval: c.int) -> bool
  52. GetExtensionsStringARBType :: #type proc "c" (HDC) -> cstring
  53. // Procedures
  54. wglCreateContextAttribsARB: CreateContextAttribsARBType
  55. wglChoosePixelFormatARB: ChoosePixelFormatARBType
  56. wglSwapIntervalEXT: SwapIntervalEXTType
  57. wglGetExtensionsStringARB: GetExtensionsStringARBType
  58. @(default_calling_convention="system")
  59. foreign Opengl32 {
  60. wglCreateContext :: proc(hdc: HDC) -> HGLRC ---
  61. wglMakeCurrent :: proc(hdc: HDC, HGLRC: HGLRC) -> BOOL ---
  62. wglGetProcAddress :: proc(c_str: cstring) -> rawptr ---
  63. wglDeleteContext :: proc(HGLRC: HGLRC) -> BOOL ---
  64. wglCopyContext :: proc(src, dst: HGLRC, mask: UINT) -> BOOL ---
  65. wglCreateLayerContext :: proc(hdc: HDC, layer_plane: c.int) -> HGLRC ---
  66. wglDescribeLayerPlane :: proc(hdc: HDC, pixel_format, layer_plane: c.int, bytes: UINT, pd: LPLAYERPLANEDESCRIPTOR) -> BOOL ---
  67. wglGetCurrentContext :: proc() -> HGLRC ---
  68. wglGetCurrentDC :: proc() -> HDC ---
  69. wglGetLayerPaletteEntries :: proc(hdc: HDC, layer_plane, start, entries: c.int, cr: ^COLORREF) -> c.int ---
  70. wglRealizeLayerPalette :: proc(hdc: HDC, layer_plane: c.int, realize: BOOL) -> BOOL ---
  71. wglSetLayerPaletteEntries :: proc(hdc: HDC, layer_plane, start, entries: c.int, cr: ^COLORREF) -> c.int ---
  72. wglShareLists :: proc(HGLRC1, HGLRC2: HGLRC) -> BOOL ---
  73. wglSwapLayerBuffers :: proc(hdc: HDC, planes: DWORD) -> BOOL ---
  74. wglUseFontBitmaps :: proc(hdc: HDC, first, count, list_base: DWORD) -> BOOL ---
  75. wglUseFontOutlines :: proc(hdc: HDC, first, count, list_base: DWORD, deviation, extrusion: f32, format: c.int, gmf: LPGLYPHMETRICSFLOAT) -> BOOL ---
  76. }
  77. // Used by vendor:OpenGL
  78. // https://www.khronos.org/opengl/wiki/Load_OpenGL_Functions#Windows
  79. gl_set_proc_address :: proc(p: rawptr, name: cstring) {
  80. func := wglGetProcAddress(name)
  81. switch uintptr(func) {
  82. case 0, 1, 2, 3, ~uintptr(0):
  83. module := LoadLibraryW(L("opengl32.dll"))
  84. func = GetProcAddress(module, name)
  85. }
  86. (^rawptr)(p)^ = func
  87. }