<commit_before>; Platform independent OpenGL Library part
(define-library (OpenGL)
(export

   ; GL types
   ; https://www.opengl.org/wiki/OpenGL_Type
   GLenum                     ; unsigned 32-bit
   GLboolean GLboolean*       ; unsigned byte (GL_TRUE or GL_FALSE)
   GLbitfield                 ; unsigned 32-bit
   GLbyte                     ;   signed  8-bit
   GLshort  GLshort*          ;   signed 16-bit
   GLint    GLint*   GLint&   ;   signed 32-bit
   GLsizei                    ;   signed 32-bit
   GLubyte  GLubyte*          ; unsigned  8-bit
   GLushort GLushort*         ; unsigned 16-bit
   GLuint   GLuint*  GLuint&  ; unsigned 32-bit

   GLfloat  GLfloat*  ; floating 32-bit
   GLclampf           ; floating 32-bit (clamped to the range [0,1])
   GLdouble GLdouble* ; floating 64-bit
   GLclampd           ; floating 64-bit (clamped to the range [0,1])

   GLvoid   GLvoid*       ; void, void*

   ; minimal GL function set
   glGetString
      GL_VENDOR
      GL_RENDERER
      GL_VERSION
      GL_EXTENSIONS

   ; WGL/GLX/CGL/EGL/... universal functions
   gl:GetProcAddress

   gl:CreateContext ; context creation
   gl:MakeCurrent
   gl:SwapBuffers
   gl:QueryExtension

   ; internal variables
   GL GLX WGL GDI EGL
   GL_LIBRARY ; deprecated

   (exports (otus lisp))
   (exports (otus ffi)))

; ============================================================================
; == implementation ==========================================================
(import (otus lisp) (otus ffi))

(begin
   ; https://en.wikipedia.org/wiki/Uname
   (setq OS (ref (uname) 1))

   (setq win32? (string-ci=? OS "Windows"))
   (setq linux? (string-ci=? OS "Linux"))
   (setq apple? (string-ci=? OS "Darwin"))

   (setq GL_LIBRARY (load-dynamic-library
      (cond
         (win32? "opengl32")
         (linux? "libGL.so.1")
         ;"HP-UX"
         ;"SunOS"
         ;"Darwin"
         ;"FreeBSD"
         ;"CYGWIN_NT-5.2-WOW64"
         ;"MINGW32_NT-5.2"
         ;...
         (else
            (runtime-error "Unsupported platform" OS)))))

   (define GL GL_LIBRARY)

   (define GLX (if linux? GL_LIBRARY))
   (define WGL (if win32? GL_LIBRARY))
   (define GDI (if win32? (load-dynamic-library "gdi32.dll")))
   (define EGL #false) ;TODO

   ; -------------------------------------------------------------------------
   ; -- types
   (define GLvoid   fft-void)
   (define GLvoid*  fft-void*)

   (define GLenum     fft-unsigned-int)
   (define GLboolean  fft-unsigned-char)
   (define GLbitfield fft-unsigned-int)

   (define GLbyte   fft-signed-char)
   (define GLshort  fft-short)
   (define GLint    fft-int)
   (define GLsizei  fft-int)
   (define GLubyte  fft-unsigned-char)
   (define GLushort fft-unsigned-short)
   (define GLuint   fft-unsigned-int)

   (define GLfloat  fft-float)
   (define GLclampf fft-float)
   (define GLdouble fft-double)
   (define GLclampd fft-double)

   (define GLubyte* type-string) ; todo: ?

   ; pointers
   (define GLboolean* (fft* GLboolean))
   (define GLshort*   (fft* GLshort))
   (define GLushort*  (fft* GLushort))
   (define GLint*     (fft* GLint))
   (define GLuint*    (fft* GLuint))
   (define GLfloat*   (fft* GLfloat))
   (define GLdouble*  (fft* GLdouble))

   ; references
   (define GLint&     (fft& GLint))
   (define GLuint&    (fft& GLuint))
   ; -------------------------------------------------------------------------

   ; Strings GL_VENDOR and GL_RENDERER together uniquely specify a platform.
   ; They do not change from release to release and    ; should be used by platform-recognition algorithms.
   (define GL_VENDOR     #x1F00)
   (define GL_RENDERER   #x1F01)
   (define GL_VERSION    #x1F02)
   (define GL_EXTENSIONS #x1F03)
   (define glGetString (GL type-string "glGetString" fft-unsigned-int))

; -------------------------------------------------------------------------
; WGL context creation https://www.GL.org/wiki/Creating_an_OpenGL_Context_(WGL)<commit_msg>minimal opengl set updated<commit_after>; Platform independent OpenGL Library part
(define-library (OpenGL)
(export

   ; GL types
   ; https://www.opengl.org/wiki/OpenGL_Type
   GLenum                     ; unsigned 32-bit
   GLboolean GLboolean*       ; unsigned byte (GL_TRUE or GL_FALSE)
   GLbitfield                 ; unsigned 32-bit
   GLbyte                     ;   signed  8-bit
   GLshort  GLshort*          ;   signed 16-bit
   GLint    GLint*   GLint&   ;   signed 32-bit
   GLsizei                    ;   signed 32-bit
   GLubyte  GLubyte*          ; unsigned  8-bit
   GLushort GLushort*         ; unsigned 16-bit
   GLuint   GLuint*  GLuint&  ; unsigned 32-bit

   GLfloat  GLfloat*  ; floating 32-bit
   GLclampf           ; floating 32-bit (clamped to the range [0,1])
   GLdouble GLdouble* ; floating 64-bit
   GLclampd           ; floating 64-bit (clamped to the range [0,1])

   GLvoid   GLvoid*       ; void, void*

   ; minimal required GL function set
   glGetString
      GL_VENDOR
      GL_RENDERER
      GL_VERSION
      GL_EXTENSIONS
   glViewport

   ; WGL/GLX/CGL/EGL/... universal functions
   gl:GetProcAddress

   gl:CreateContext ; context creation
   gl:MakeCurrent
   gl:SwapBuffers
   gl:QueryExtension

   ; internal variables
   GL GLX WGL GDI EGL
   GL_LIBRARY ; deprecated

   (exports (otus lisp))
   (exports (otus ffi)))

; ============================================================================
; == implementation ==========================================================
(import (otus lisp) (otus ffi))

(begin
   ; https://en.wikipedia.org/wiki/Uname
   (setq OS (ref (uname) 1))

   (setq win32? (string-ci=? OS "Windows"))
   (setq linux? (string-ci=? OS "Linux"))
   (setq apple? (string-ci=? OS "Darwin"))

   (setq GL_LIBRARY (load-dynamic-library
      (cond
         (win32? "opengl32")
         (linux? "libGL.so.1")
         ;"HP-UX"
         ;"SunOS"
         ;"Darwin"
         ;"FreeBSD"
         ;"CYGWIN_NT-5.2-WOW64"
         ;"MINGW32_NT-5.2"
         ;...
         (else
            (runtime-error "Unsupported platform" OS)))))

   (define GL GL_LIBRARY)

   (define GLX (if linux? GL_LIBRARY))
   (define WGL (if win32? GL_LIBRARY))
   (define GDI (if win32? (load-dynamic-library "gdi32.dll")))
   (define EGL #false) ;TODO

   ; -------------------------------------------------------------------------
   ; -- types
   (define GLvoid   fft-void)
   (define GLvoid*  fft-void*)

   (define GLenum     fft-unsigned-int)
   (define GLboolean  fft-unsigned-char)
   (define GLbitfield fft-unsigned-int)

   (define GLbyte   fft-signed-char)
   (define GLshort  fft-short)
   (define GLint    fft-int)
   (define GLsizei  fft-int)
   (define GLubyte  fft-unsigned-char)
   (define GLushort fft-unsigned-short)
   (define GLuint   fft-unsigned-int)

   (define GLfloat  fft-float)
   (define GLclampf fft-float)
   (define GLdouble fft-double)
   (define GLclampd fft-double)

   (define GLubyte* type-string) ; todo: ?

   ; pointers
   (define GLboolean* (fft* GLboolean))
   (define GLshort*   (fft* GLshort))
   (define GLushort*  (fft* GLushort))
   (define GLint*     (fft* GLint))
   (define GLuint*    (fft* GLuint))
   (define GLfloat*   (fft* GLfloat))
   (define GLdouble*  (fft* GLdouble))

   ; references
   (define GLint&     (fft& GLint))
   (define GLuint&    (fft& GLuint))
   ; -------------------------------------------------------------------------

   ; Strings GL_VENDOR and GL_RENDERER together uniquely specify a platform.
   ; They do not change from release to release and    ; should be used by platform-recognition algorithms.
   (define GL_VENDOR     #x1F00)
   (define GL_RENDERER   #x1F01)
   (define GL_VERSION    #x1F02)
   (define GL_EXTENSIONS #x1F03)
   (define glGetString (GL type-string "glGetString" fft-unsigned-int))
   (define glViewport (GL GLvoid "glViewport" GLint GLint GLsizei GLsizei))

; -------------------------------------------------------------------------
; WGL context creation https://www.GL.org/wiki/Creating_an_OpenGL_Context_(WGL)
{'fraction_non_alphanumeric': 0.18821767348976534, 'fraction_numerical': 0.01547678482276585, 'mean_word_length': 2.107018224117875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7208003', 'n_tokens_mistral': 2776, 'n_tokens_neox': 2613, 'n_words': 657}