Hello,
I am trying to implement a 3D engine from scratch with XCB. To do this, I
have to set the color of every individual pixel before drawing it.

I noticed that calling xcb_alloc_color and xcb_alloc_color_reply are
bottlenecking the program and making it slow to draw individual triangles.

Below is how I am setting the color before drawing each pixel, straight
from this tutorial
<https://www.x.org/releases/X11R7.7/doc/libxcb/tutorial/index.html#usecolor>
:

void set_drawing_color(xcb_connection_t *c, xcb_colormap_t colormap,
xcb_gcontext_t gcontext, int r, int g, int b) {
    xcb_alloc_color_reply_t *color_info;
    uint32_t mask;
    uint32_t value[3];
    color_info = xcb_alloc_color_reply(c, xcb_alloc_color(c, colormap,
r, g, b), NULL);

    if (!color_info)
        return 0;
    free(color_info);

    mask = XCB_GC_FOREGROUND;
    value[0] = color_info->pixel;
    xcb_change_gc(c, gcontext, mask, value);}

Is this an appropriate way to set the color? Is there a more efficient
way to do so?

Slightly unrelated question: as someone completely new to Xorg and
Linux graphics in general,
how do you deal with the lack of documentation for XCB?

Thanks,

Mark
_______________________________________________
xorg@lists.x.org: X.Org support
Archives: http://lists.freedesktop.org/archives/xorg
Info: https://lists.x.org/mailman/listinfo/xorg
Your subscription address: %(user_address)s

Reply via email to