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!d16g2000yqb.googlegroups.com!not-for-mail From: Gene Newsgroups: comp.lang.ada Subject: Re: OpenGL in Ada Date: Fri, 9 Jul 2010 13:54:36 -0700 (PDT) Organization: http://groups.google.com Message-ID: <2074b3a5-12f3-4260-a2ad-f15ed251e378@d16g2000yqb.googlegroups.com> References: <68dd0333-f502-4351-9e50-4ec83bddc44e@k39g2000yqd.googlegroups.com> NNTP-Posting-Host: 184.12.82.25 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1278708877 15785 127.0.0.1 (9 Jul 2010 20:54:37 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 9 Jul 2010 20:54:37 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d16g2000yqb.googlegroups.com; posting-host=184.12.82.25; posting-account=-BkjswoAAACC3NU8b6V8c50JQ2JBOs04 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16,gzip(gfe) Xref: g2news1.google.com comp.lang.ada:12298 Date: 2010-07-09T13:54:36-07:00 List-Id: On Jul 9, 1:38=A0pm, Shark8 wrote: > 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 g= reen, > > > GLdouble blue); > > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3dv (const GLdouble *v); > > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3f (GLfloat red, GLfloat gre= en, > > > GLfloat blue); > > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3fv (const GLfloat *v); > > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3i (GLint red, GLint green, = GLint > > > blue); > > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3iv (const GLint *v); > > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3s (GLshort red, GLshort gre= en, > > > GLshort blue); > > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3sv (const GLshort *v); > > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3ub (GLubyte red, GLubyte gr= een, > > > GLubyte blue); > > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3ubv (const GLubyte *v); > > > =A0 =A0 * WINGDIAPI void APIENTRY glColor3ui (GLuint red, GLuint gree= n, > > > 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 g= reen, > > > GLdouble blue, GLdouble alpha); > > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4dv (const GLdouble *v); > > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4f (GLfloat red, GLfloat gre= en, > > > GLfloat blue, GLfloat alpha); > > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4fv (const GLfloat *v); > > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4i (GLint red, GLint green, = GLint > > > blue, GLint alpha); > > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4iv (const GLint *v); > > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4s (GLshort red, GLshort gre= en, > > > GLshort blue, GLshort alpha); > > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4sv (const GLshort *v); > > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4ub (GLubyte red, GLubyte gr= een, > > > GLubyte blue, GLubyte alpha); > > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4ubv (const GLubyte *v); > > > =A0 =A0 * WINGDIAPI void APIENTRY glColor4ui (GLuint red, GLuint gree= n, > > > 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_Byt= e ); > > > =A0Procedure Color =A0 =A0( v: RGBA_Unsigned_Byte_Vector ); > > > =A0Procedure Color =A0 =A0( red, green, blue, alpha : in Unsigned_Int= eger ); > > > =A0Procedure Color =A0 =A0( v: RGBA_Unsigned_Integer_Vector ); > > > =A0Procedure Color =A0 =A0( red, green, blue, alpha : in Unsigned_Sho= rt ); > > > =A0Procedure Color =A0 =A0( v: RGBA_Unsigned_Short_Vector ); > > > > where X_Y_Vector is an array of elements of type Y and indexed on typ= e > > > 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 graphic= s > > hardware continues to evolve. =A0Compilers will always have their uniqu= e > > 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. Well, plus the need for backward compatibility. Nonetheless, if you have isolated the need to identify glBegin args in a table within a translator, so it can spit out the requisite new enumeration equivalences, I believe you are ahead of the game. No one is saying the translator will keep working with zero modifications. For (an admittedly contrived) example, if the spec introduces a new call that accepts anything glBegin will accept plus a few other flags, the translator can encode this idea in a new addendum table and an algorithm. This is easier and less error prone going forward than remembering to update both enumerations in parallel.