PDA

View Full Version : How to draw directly to memory buffer? Help



bubbaJr
01-27-2005, 05:55 AM
I've created four windows using OpenGLUT, and each window will have unique contents, so I need 4 buffers. My system doesn't have enough framebuffers (no AUX buffers) so I've got to create my own buffers, which I've done:

char* BufferA[ WIDTH ][ HEIGHT ][ 3 ];
char* BufferB[ WIDTH ][ HEIGHT ][ 3 ];
char* BufferC[ WIDTH ][ HEIGHT ][ 3 ];
char* BufferD[ WIDTH ][ HEIGHT ][ 3 ];

my display routines look like:

glDrawBuffer(GL_FRONT_LEFT);
glRasterPos3i( 0, 0, 0 );
glDrawPixels( WIDTH, HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, BufferA );
glFlush();

But I can tell I'm writing to BufferA in a clumsy fashion:

glDrawBuffer(GL_BACK_LEFT);
glDrawPixels( 640, 480, GL_RGB, GL_UNSIGNED_BYTE, BufferA );

// some glBegin - glEnd stuff

glReadBuffer(GL_BACK_LEFT);
glReadPixels( 0, 0, WIDTH, HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, BufferA );

When I draw to the buffer I'm:
1. putting the current contents of the memory buffer into the framebuffer
2. drawing to the framebuffer
3. reading the framebuffer back into the memory buffer.

I need to draw directly into the memory buffer. How is that done?

NOTE: Was able to use the above clumsy method with 4 different windows quite successfully (seems simultaneous) using a NVIDIA Quadro4 750 XGL/AGP/SSE2 video card with Windows 2000. But when I run the same thing on a Windows 200 workstation with a GDI Generic video card, I get abysmall performance, totally unacceptable. However, our code is targeted for the slower, less capable machine, so I've got to deal with it.

-bBrain

dvm
01-28-2005, 10:23 AM
I think you're making a bit of a mistake here. The left and right buffers are used for stereo rendering on perhaps 2 screens or special hardware. The reason you're getting weird results is that not all cards support the left and right buffers.
Since you already have 4 glut windows you should have 4 different render functions. So then what's your problem? Each function will render to its own back buffer and after swapping buffers you should be ok. You don't need to be messing with buffers yourself (except for swapping them). GLUT will take care of the rest for you.
If you still need direct access to the memory buffer I don't think OpenGL provides one. You could check sdl for that with pixel granularity, but then we're probable talking having to create your own primitive drawing function, which apart from the fact that it will take you a lot of time to do it, I doubt that the end result will be faster than what you would achiece with opengl.

Aeluned
01-28-2005, 11:28 AM
You can't draw directly to a memory buffer. The result of a sequence of draw calls is deposited directly into onboard (video) memory. If you want to get it into system memory after that you're going to have to do a ReadPixels or the like. This shouldn't come as a surprise; imagine if each time a fragment was to be drawn to the frame buffer it would have to travel through the system bus to get to it's final resting place. It's faster to render to the onboard buffer and then batch read the data into system memory.

pushing frame buffer contents around sucks, but sometimes there's no other way around it - sometimes there is (FBO,RTT).