ifndef                  _EXTENSIONS_ASM
_EXTENSIONS_ASM         equ     1

; ------------------------------------------------------
; Variables
wglGetExtensionsStringARB PFNWGLGETEXTENSIONSSTRINGARBPROC 0

; ------------------------------------------------------
; Name: Check_Extension()
; Desc: Check whether an opengl extension is available or not
Check_Extension         proc    uses ebx esi edi Extension_Name:dword
                        local   Done_Extensions:dword
                        local   hDC:HDC
                        local   Len_Extension_Name:dword
                        local   Extensions_List:dword
                        local   First_Extension_Length:dword

                        mov     Done_Extensions,0
                        push    Extension_Name
                        call    strlen
                        mov     Len_Extension_Name,eax
                        
                        invoke  glGetString, GL_EXTENSIONS
                        mov     Extensions_List,eax
Check_Extra_Extensions:
                        .if     Extension_Name == NULL || Extensions_List == NULL
                                xor     eax,eax
                                ret
                        .endif
                        
                        mov     esi,Extensions_List
                        .while  byte ptr [esi] != 0
                                push    CSTR(" ")
                                push    esi
                                call    strcspn 
                                mov     First_Extension_Length,eax
                                .if     Len_Extension_Name == eax
                                        push    First_Extension_Length
                                        push    esi
                                        push    Extension_Name
                                        call    strncmp
                                        .if     eax == 0
                                                mov     eax,TRUE
                                                ret
                                        .endif
                                .endif
                                mov     eax,First_Extension_Length
                                inc     eax
                                add     esi,eax
                        .endw

                        ; Extra windows extensions
                        .if     Done_Extensions == 0
                                invoke  wglGetProcAddress, CSTR("wglGetExtensionsStringARB")
                                mov     wglGetExtensionsStringARB,eax
                                .if     wglGetExtensionsStringARB != NULL
                                        invoke  GetDC, NULL
                                        mov     hDC,eax
                                        invoke  wglGetExtensionsStringARB, hDC
                                        mov     Extensions_List,eax
                                        invoke  ReleaseDC, NULL, hDC
                                        mov     Done_Extensions, TRUE
                                        jmp     Check_Extra_Extensions
                                .endif
                        .endif
                        xor     eax,eax
                        ret
Check_Extension         endp

endif