Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Highly Disappointed w/ the new XML API Database

  1. #11
    Junior Member Regular Contributor
    Join Date
    Aug 2007
    Location
    Adelaide, South Australia
    Posts
    206
    As an example, to create a strongly-typed OpenGL header file for Pascal, you would do something like this:
    Lets try glCullFace, in the XML file we find a list of valid enums for it, but the type name is a comment which makes it hard to extract.
    Code :
    <!-- /* CullFaceMode */ --> 
    <enum name="GL_FRONT" /> 
    <enum name="GL_BACK" /> 
    <enum name="GL_FRONT_AND_BACK" />
    The actual values are easy:
    Code :
      <enum value="0x0404" name="GL_FRONT" /> 
    <enum value="0x0405" name="GL_BACK" /> 
      <enum value="0x0408" name="GL_FRONT_AND_BACK" />
    From this we can define a Pascal type:
    Code :
    CullFaceMode = (
            GL_FRONT = $0404,
            GL_BACK = $0405,
            GL_FRONT_AND_BACK = $0408
            );
    Now for the command:
    Code :
    <command>
     <proto>
      void 
      <name>glCullFace</name> 
      </proto>
     <param>
      <ptype>GLenum</ptype> 
      <name>mode</name> 
      </param>
      <glx type="render" opcode="79" /> 
      </command>
    Not very helpful, the parameter is only listed as GLenum, what we need is some way to create this:
    Code :
    type
    TCullFace = procedure glCullface( mode: CullFaceMode );
    var
    glCullFace: TCullFace;

    For commands like GetIntegerv you could overload the function definition so that if the enum is in one range of values then the second parameter must be a pointer to an integer variable, and for another range it must be a pointer to an array of integer.
    For some enums you might specify that it is a pointer to a record type, for example if you are reading a color value you might make a record type containing R,G,B and A values.
    This would need the information from the state tables in chapter 23 of the spec.

  2. #12
    Junior Member Regular Contributor
    Join Date
    Dec 2009
    Posts
    198
    How would your strongly typed Pascal binding deal with glDrawBuffer(), which accepts GL_FRONT, GL_BACK, GL_FRONT_AND_BACK, but also GL_NONE, GL_FRONT_LEFT, GL_FRONT_RIGHT, etc. ?

  3. #13
    Junior Member Regular Contributor
    Join Date
    Aug 2007
    Location
    Adelaide, South Australia
    Posts
    206
    Lots and lots of overloading

    Heavily reused enums will need there own type eNone = ( GL_NONE = 0 ); // [ DrawBufferMode ],[ PixelTexGenMode ]
    eBothFaces = ( GL_FRONT_AND_BACK = $0408 ); //[ DrawBufferMode ], [ ColorMaterialFace ],[ CullFaceMode ],[ MaterialFace ]

    Then we do the main enum type:
    eDrawBufferMode = (
    GL_FRONT_LEFT = $0400, //[ DrawBufferMode ],[ ReadBufferMode ]
    GL_FRONT_RIGHT = $0401, //[ DrawBufferMode ],[ ReadBufferMode ]
    GL_BACK_LEFT = $0402, //[ DrawBufferMode ],[ ReadBufferMode ]
    GL_BACK_RIGHT = $0403, //[ DrawBufferMode ],[ ReadBufferMode ]
    GL_FRONT = $0404, //[ DrawBufferMode ],[ ReadBufferMode ],[ ColorMaterialFace ],[ CullFaceMode ],[ MaterialFace ]
    GL_BACK = $0405, //[ DrawBufferMode ],[ ReadBufferMode ],[ ColorMaterialFace ],[ CullFaceMode ],[ MaterialFace ]
    GL_LEFT = $0406, //[ DrawBufferMode ],[ ReadBufferMode ]
    GL_RIGHT = $0407 ); //[ DrawBufferMode ],[ ReadBufferMode ]

    Some reused enums are ranges inside of larger types so we can take the type for DrawBufferMode/ReadBufferMode and create a subrange type for ColorMaterialFace/CullFaceMode/MaterialFace:
    eCullFaceMode = GL_FRONT..GL_BACK;

    Then once we have the enums divided up into groups, we just overload the function to use all of the applicable groups.
    procedure glDrawBuffer( Buffers: eNone ); stdcall; external 'OpenGL32.dll'; overload;
    procedure glDrawBuffer( Buffers: eDrawBufferMode ); stdcall; external 'OpenGL32.dll'; overload;
    procedure glDrawBuffer( Buffers: eBothFaces ); stdcall; external 'OpenGL32.dll'; overload;

  4. #14
    Administrator Contributor
    Join Date
    Jan 2002
    Location
    Mt. View, CA
    Posts
    97
    FYI, I've put the .spec file parameter type & array length annotations into gl.xml. See here and feel free to provide feedback on the board, or patches in Bugzilla, if this helps address the concerns in this thread.
    Jon Leech
    Khronos API Registrar
    ARB Ecosystem TSG Chair
    GL/EGL/GLES Spec Editor
    ...and suchlike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •