From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5b7ee26df9f9c357 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!r27g2000yqb.googlegroups.com!not-for-mail From: Shark8 Newsgroups: comp.lang.ada Subject: Re: OpenGL in Ada Date: Fri, 9 Jul 2010 10:38:56 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <68dd0333-f502-4351-9e50-4ec83bddc44e@k39g2000yqd.googlegroups.com> NNTP-Posting-Host: 174.28.205.195 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1278697136 8823 127.0.0.1 (9 Jul 2010 17:38:56 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 9 Jul 2010 17:38:56 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: r27g2000yqb.googlegroups.com; posting-host=174.28.205.195; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.10) Gecko/20100504 Firefox/3.5.10 ( .NET CLR 3.5.30729; .NET CLR 4.0.20506),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:12293 Date: 2010-07-09T10:38:56-07:00 List-Id: On Jul 9, 9:11=A0am, Gene wrote: > On Jul 7, 10:42=A0pm, Shark8 wrote: > > > > > Hello everyone, > > I posted about wanting to write an OS in Ada a while ago and, as part > > of that effort I've taken to translating the OpenGL API. No, I don't > > mean JUST running the headers through ato-Ada converter but actually > > translating the API into a more Ada-natural form. > > > As an example, here is the glColor-'family' of functions: > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3b (GLbyte red, GLbyte green, > > GLbyte blue); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3bv (const GLbyte *v); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3d (GLdouble red, GLdouble gre= en, > > GLdouble blue); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3dv (const GLdouble *v); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3f (GLfloat red, GLfloat green= , > > GLfloat blue); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3fv (const GLfloat *v); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3i (GLint red, GLint green, GL= int > > blue); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3iv (const GLint *v); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3s (GLshort red, GLshort green= , > > GLshort blue); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3sv (const GLshort *v); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3ub (GLubyte red, GLubyte gree= n, > > GLubyte blue); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3ubv (const GLubyte *v); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3ui (GLuint red, GLuint green, > > GLuint blue); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3uiv (const GLuint *v); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3us (GLushort red, GLushort > > green, GLushort blue); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3usv (const GLushort *v); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4b (GLbyte red, GLbyte green, > > GLbyte blue, GLbyte alpha); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4bv (const GLbyte *v); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4d (GLdouble red, GLdouble gre= en, > > GLdouble blue, GLdouble alpha); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4dv (const GLdouble *v); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4f (GLfloat red, GLfloat green= , > > GLfloat blue, GLfloat alpha); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4fv (const GLfloat *v); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4i (GLint red, GLint green, GL= int > > blue, GLint alpha); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4iv (const GLint *v); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4s (GLshort red, GLshort green= , > > GLshort blue, GLshort alpha); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4sv (const GLshort *v); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4ub (GLubyte red, GLubyte gree= n, > > GLubyte blue, GLubyte alpha); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4ubv (const GLubyte *v); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4ui (GLuint red, GLuint green, > > GLuint blue, GLuint alpha); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4uiv (const GLuint *v); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4us (GLushort red, GLushort > > green, GLushort blue, GLushort alpha); > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4usv (const GLushort *v); > > > which was rewritten as: > > =A0-- Color Formats > > =A0Procedure Color =A0 =A0( red, green, blue : in Byte ); > > =A0Procedure Color =A0 =A0( v : RGB_Byte_Vector ); > > =A0Procedure Color =A0 =A0( red, green, blue : in double ); > > =A0Procedure Color =A0 =A0( v : RGB_Double_Vector ); > > =A0Procedure Color =A0 =A0( red, green, blue : in float ); > > =A0Procedure Color =A0 =A0( V : RGB_Float_Vector ); > > =A0Procedure Color =A0 =A0( red, green, blue : int ); > > =A0Procedure Color =A0 =A0( V : RGB_Integer_Vector ); > > =A0Procedure Color =A0 =A0( red, green, blue : Short ); > > =A0Procedure Color =A0 =A0( V : RGB_Short_Vector ); > > =A0Procedure Color =A0 =A0( red, green, blue : Unsigned_Byte ); > > =A0Procedure Color =A0 =A0( v : RGB_Unsigned_Byte_Vector ); > > =A0Procedure Color =A0 =A0( red, green, blue : in Unsigned_Integer ); > > =A0Procedure Color =A0 =A0( v : RGB_Unsigned_Integer_Vector ); > > =A0Procedure Color =A0 =A0( red, green, blue : in Unsigned_Short ); > > =A0Procedure Color =A0 =A0( v : RGB_Unsigned_Short_Vector ); > > =A0Procedure Color =A0 =A0( red, green, blue, alpha : in byte ); > > =A0Procedure Color =A0 =A0( v: RGBA_Byte_Vector ); > > =A0Procedure Color =A0 =A0( red, green, blue, alpha : in double ); > > =A0Procedure Color =A0 =A0( v : RGBA_Double_Vector ); > > =A0Procedure Color =A0 =A0( red, green, blue, alpha : in float ); > > =A0Procedure Color =A0 =A0( v: RGBA_Float_Vector ); > > =A0Procedure Color =A0 =A0( red, green, blue, alpha : in int ); > > =A0Procedure Color =A0 =A0( v: RGBA_Integer_Vector ); > > =A0Procedure Color =A0 =A0( red, green, blue, alpha : in short ); > > =A0Procedure Color =A0 =A0( v: RGBA_Short_Vector ); > > =A0Procedure Color =A0 =A0( red, green, blue, alpha : in Unsigned_Byte = ); > > =A0Procedure Color =A0 =A0( v: RGBA_Unsigned_Byte_Vector ); > > =A0Procedure Color =A0 =A0( red, green, blue, alpha : in Unsigned_Integ= er ); > > =A0Procedure Color =A0 =A0( v: RGBA_Unsigned_Integer_Vector ); > > =A0Procedure Color =A0 =A0( red, green, blue, alpha : in Unsigned_Short= ); > > =A0Procedure Color =A0 =A0( v: RGBA_Unsigned_Short_Vector ); > > > where X_Y_Vector is an array of elements of type Y and indexed on type > > X. > > > Another thing that I've done is, to the best of my ability, used Ada's > > strong typing to make passing invalid parameters less of a problem; > > for example: > > =A0 =A0Type Begin_Mode_Type is > > =A0 =A0 =A0( =A0POINTS, LINES, LINE_LOOP, LINE_STRIP, TRIANGLES, > > TRIANGLE_STRIP, > > =A0 =A0 =A0 =A0 TRIANGLE_FAN, QUADS, QUAD_STRIP, POLYGON > > =A0 =A0 =A0); > > > =A0 =A0 For Begin_Mode_Type use > > =A0 =A0 =A0( =A0POINTS =A0 =A0 =A0 =A0 =A0=3D> GL_POINTS, > > =A0 =A0 =A0 =A0 LINES =A0 =A0 =A0 =A0 =A0 =3D> GL_LINES, > > =A0 =A0 =A0 =A0 LINE_LOOP =A0 =A0 =A0 =3D> GL_LINE_LOOP, > > =A0 =A0 =A0 =A0 LINE_STRIP =A0 =A0 =A0=3D> GL_LINE_STRIP, > > =A0 =A0 =A0 =A0 TRIANGLES =A0 =A0 =A0 =3D> GL_TRIANGLES, > > =A0 =A0 =A0 =A0 TRIANGLE_STRIP =A0=3D> GL_TRIANGLE_STRIP, > > =A0 =A0 =A0 =A0 TRIANGLE_FAN =A0 =A0=3D> GL_TRIANGLE_FAN, > > =A0 =A0 =A0 =A0 QUADS =A0 =A0 =A0 =A0 =A0 =3D> GL_QUADS, > > =A0 =A0 =A0 =A0 QUAD_STRIP =A0 =A0 =A0=3D> GL_QUAD_STRIP, > > =A0 =A0 =A0 =A0 POLYGON =A0 =A0 =A0 =A0 =3D> GL_POLYGON > > =A0 =A0 =A0); > > > is a type for the glBegin-wrapper which only allows the =A0passing of > > valid "mode"-parameters. {That is, range points..polygon.} > > > My questions are these: > > Would anyone, other than myself, find such a translation of interest? > > and > > When I finish, would anyone want to test it out? > > Having done this a couple of times myself, you should consider the > approach of writing a specialized program that processes the OpenGL > header into a binding. =A0OpenGL will remain a moving target as graphics > hardware continues to evolve. =A0Compilers will always have their unique > quirks. =A0With all this room for variation, it will probably be easier > to maintain a translator than to revise the binding every time the > standard changes or grows. I see what you're saying. The problem is in the specs, the moving target you mentioned, for example the glBegin function could be extended to take a new enumeration, say, GL_AWESOME! This disrupts the allowable inputs for glBegin, now we have a non-contiguous range of GL_POINTS..GL_POLYGON & GL_AWESOME..GL_AWESOME since these are constants instead of true enumeration-types {thank you c/c++} and the glFUNCTIONs take a 32-bit value as the "enumeration." Basically it's the result of a) lack of foresight, and b) lazy programming.