From: W Dan Meyer <wojciech.meyer@googlemail.com>
To: "Török Edwin" <edwintorok@gmail.com>
Cc: Wojciech Meyer <wojciech.meyer@googlemail.com>, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Converting variants with only constant constructors to integers
Date: Mon, 07 Jun 2010 19:50:33 +0100 [thread overview]
Message-ID: <87bpbm7k3q.fsf@gmail.com> (raw)
In-Reply-To: <4C0D3B3E.5050408@gmail.com> (=?utf-8?B?IlTDtnLDtms=?= Edwin"'s message of "Mon, 07 Jun 2010 21:32:30 +0300")
Török Edwin <edwintorok@gmail.com> writes:
>
> Yes, I probably should have started with that.
> I have some flags like:
> type myflags = Property1 | Property2 | Property3;;
Hmm, you can take a look at lablgl sources, they use a lot this kind of
constructs.
Here is the answer:
CAMLprim value ml_glPushAttrib (value list)
{
GLbitfield mask = 0;
while (list != Val_int(0)) {
switch (Field(list,0)) {
case MLTAG_accum_buffer:mask |= GL_ACCUM_BUFFER_BIT; break;
case MLTAG_color_buffer:mask |= GL_COLOR_BUFFER_BIT; break;
case MLTAG_current: mask |= GL_CURRENT_BIT; break;
case MLTAG_depth_buffer:mask |= GL_DEPTH_BUFFER_BIT; break;
case MLTAG_enable: mask |= GL_ENABLE_BIT; break;
case MLTAG_eval: mask |= GL_EVAL_BIT; break;
case MLTAG_fog: mask |= GL_FOG_BIT; break;
case MLTAG_hint: mask |= GL_HINT_BIT; break;
case MLTAG_lighting: mask |= GL_LIGHTING_BIT; break;
case MLTAG_line: mask |= GL_LINE_BIT; break;
case MLTAG_list: mask |= GL_LIST_BIT; break;
case MLTAG_pixel_mode: mask |= GL_PIXEL_MODE_BIT; break;
case MLTAG_point: mask |= GL_POINT_BIT; break;
case MLTAG_polygon: mask |= GL_POLYGON_BIT; break;
case MLTAG_polygon_stipple:mask |= GL_POLYGON_STIPPLE_BIT; break;
case MLTAG_scissor: mask |= GL_SCISSOR_BIT; break;
case MLTAG_stencil_buffer:mask |= GL_STENCIL_BUFFER_BIT; break;
case MLTAG_texture: mask |= GL_TEXTURE_BIT; break;
case MLTAG_transform: mask |= GL_TRANSFORM_BIT; break;
case MLTAG_viewport: mask |= GL_VIEWPORT_BIT; break;
}
list = Field(list,1);
}
glPushAttrib (mask);
return Val_unit;
}
where is the MLTAG is define like this:
struct record {
value key;
GLenum data;
};
static struct record input_table[] = {
#include "gl_tags.c"
};
where:
{MLTAG_color, GL_COLOR},
{MLTAG_depth, GL_DEPTH},
{MLTAG_accum, GL_ACCUM},
{MLTAG_stencil, GL_STENCIL},
{MLTAG_points, GL_POINTS},
where:
#define MLTAG_color Val_int(-899911325)
#define MLTAG_depth Val_int(-685117181)
(...)
aha!
-rwxr-xr-x 1 spec spec 86334 2010-05-31 13:51 var2switch
-rwxr-xr-x 1 spec spec 81183 2010-05-31 13:51 var2def
plus this:
gl_tags.var:
(* GLenum *)
color
depth
accum
stencil
points
lines
polygon
triangles
quads
line_strip
line_loop
triangle_strip
triangle_fan
quad_strip
(...)
gives an answer: they are generated from OCaml code.
> Best regards,
> --Edwin
Wojciech
next prev parent reply other threads:[~2010-06-07 18:51 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-07 18:07 Török Edwin
2010-06-07 18:25 ` [Caml-list] " W Dan Meyer
2010-06-07 18:45 ` bluestorm
[not found] ` <87sk4y7lc7.fsf@gmail.com>
[not found] ` <4C0D3B0F.4060502@gmail.com>
2010-06-07 18:32 ` Török Edwin
2010-06-07 18:50 ` W Dan Meyer [this message]
2010-06-07 18:48 ` David Allsopp
2010-06-07 19:46 ` Török Edwin
2010-06-07 19:56 ` bluestorm
2010-06-07 22:51 ` W Dan Meyer
2010-06-08 7:42 ` David Allsopp
2010-06-08 7:59 ` bluestorm
2010-06-08 9:14 ` David Allsopp
2010-06-08 9:36 ` Luc Maranget
2010-06-08 9:45 ` David Allsopp
2010-06-08 9:51 ` Luc Maranget
2010-06-08 10:21 ` David Allsopp
2010-06-08 10:21 ` Dario Teixeira
2010-06-08 11:28 ` Kaustuv Chaudhuri
2010-06-08 11:40 ` bluestorm
2010-06-08 14:37 ` Jacques Garrigue
2010-06-08 18:22 ` Kaustuv Chaudhuri
2010-06-09 1:34 ` Jacques Garrigue
2010-08-23 14:36 ` Damien Doligez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bpbm7k3q.fsf@gmail.com \
--to=wojciech.meyer@googlemail.com \
--cc=caml-list@yquem.inria.fr \
--cc=edwintorok@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox