1

I'm trying to render a 3D scene into an array of color values and display it using xcb. I am inclined to rule out using xcb_poly_point() because it does not sound like it was designed for this.

According to this, if I want double buffering, I have to either use extensions that were already deprecated in 2009 or write to a pixmap and xcb_copy_area() it to the window, but I could not find any function to write pixels to pixmaps.

Another option I found was to use an XImage (or xcb_image_t I guess) instead of a pixmap, but there are no functions that manipulate the data array, which leads me to believe the operation is not exactly correct. Or is it?

Yet another option is to use shared memory. This seems closer to what I wanted to do ("I wrote into this array, use it"). Is this the way to go? Is there anything I should be aware of when writing to shared memory (never used it)? Should I be concerned that it is an extension?

Maeriden
  • 11
  • 4
  • 1
    The whole point of double buffering is that switching between the buffers is instantaneous, so that te user doesn't watch the buffer update process in real time. Copying pixmaps is not instantaneous. – n. m. could be an AI Feb 04 '18 at 15:44
  • Right... so the only reliable method is to use GLX? – Maeriden Feb 05 '18 at 12:46
  • Well since OpenGL is *the* API to render 3D stuff I would say it's an obvious first choice. You don't want to render to your own pixmap. Use OpenGL rendering primitives. – n. m. could be an AI Feb 05 '18 at 12:56
  • The thing is, this is for a school project. I'm supposed to write a raymarcher software renderer, but I have no idea how to give my final scene to a window. Double buffering is not strictly necessary, but I'm guessing it would look terrible without it. – Maeriden Feb 06 '18 at 10:49
  • Ah that's something different. If you only need to show the final scene, you can do it in a variety of ways. Just save a file in a simple raw RGB format and use a third party library or application to show it in a window. – n. m. could be an AI Feb 06 '18 at 10:52
  • If you need to do all of it yourself with xcb, then it is not too simple. You may need to take into account different screen depths and truecolor/colormapped screens. You want to use XImage and manipulate the data directly (no standard functions exist). There are examples of how to do that on the net, give them a search. This is how most software that shows images in X11 works (that I know at any rate). – n. m. could be an AI Feb 06 '18 at 10:57
  • You probably can steal some code from here ftp://surfer.nmr.mgh.harvard.edu/pub/dist/freesurfer/tutorial_packages/OSX/fsl_501/src/miscvis/dpng.c – n. m. could be an AI Feb 06 '18 at 11:02
  • I could do that, but honestly I wanted to make it interactive - allowing scene navigation. I ended up using EGL to set up a window and swap buffers, and glDrawPixels to upload my data. Thank you very much for your time. – Maeriden Feb 08 '18 at 13:55
  • A software raytracer will probably be too slow for interactive navigation but you can try... – n. m. could be an AI Feb 08 '18 at 19:37
  • @n.'pronouns'm. I want to render my own pixmap. No OpenGL available here and I already have a 3d software rasterizer from which I would like to just blit the results to a window. Also I have no access to third party whatever to which I can rely to do the memcpy of the pixels, nor I see the point either. – Pablo Ariel Mar 19 '21 at 17:25

1 Answers1

2

Faced with a similar challenge, wishing to fill a pixmap with data from a file and to directly manipulate, I found a great question with a great answer already waiting here on Stack Overflow!

A great answer to a question about using MIT-SHM with xcb

My toy, hobby application uses a shared memory pixmap as a buffer, directly filling it from a file. By loading the pixmap, using xcb_copy_area() to the window, and repeating, it yields over 60fps with no double buffering extension. I don't see any image tearing unless dragging the window.

That runs on an i5 M540 with integrated graphics. I'm rewriting the code to use regular old ximage's on a newer setup unsupported by MIT-SHM. I suspect it will also work fast enough to avoid the need for double buffering. Maybe not 60fps, but enough for my purposes.

Update: my newer setup is supported by MIT-SHM for using a shared memory XImage but not shared memory pixmaps. By reading from a file into the XImage, then copying from the XImage to a pixmap works pretty well-over 40fps.

Xcb is complicated and I find keeping it sweet, simple, and stupid as possible is the best way. For a minor school assignment, if it works on the machine you're writing it on, why worry? First, try the simplest approach, then get fancy.

DeeDeeK
  • 56
  • 7