|
|
Thanks for your reply.
First of all, i can't use wgl cos I use X-window and not Windows. I have to stick to glx and wglBindTexImageARB is not supported yet. I'm planning on porting that to windows later, in which case I'll use those functions of course.
Then, here is some code...
That's how I create my target texture:
// Create target texture
for (int i = 0; i < 1024*1024; i++) {
texData[i*3] = 0;
texData[(i*3) + 1] = 255;
texData[(i*3) + 2] = 0;
}
glGenTextures(1, &targetTexture);
glBindTexture(GL_TEXTURE_2D, targetTexture);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 1024, 1024, 0, GL_RGB, GL_UNSIGNED_BYTE, texData);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
free(texData);
|
That's how I create my pbuffer:
// Create a pbuffer
GLXFBConfig *config = NULL;
int FB_attribs[] = { GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
GLX_X_RENDERABLE, True,
GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
None};
int n_configs = 0;
config = glXChooseFBConfig(GLWin.dpy, 0, FB_attribs, &n_configs);
if (n_configs == 0) {
cerr << "Could not get matching frame buffer configuration" << endl;
} else {
cout << "Found " << n_configs << " matching frame buffer configurations" << endl;
int PB_attribs[] = {GLX_PBUFFER_WIDTH, 1024,
GLX_PBUFFER_HEIGHT, 1024};
pbufferCTX = glXCreateNewContext(GLWin.dpy, config[0], GLX_RGBA_TYPE, NULL, true);
pbuffer = glXCreatePbuffer(GLWin.dpy, config[0], PB_attribs);
|
And when I render I first do:
if (!glXMakeContextCurrent(GLWin.dpy, pbuffer, pbuffer, pbufferCTX) ) {
cerr << "Could not make pbuffer the current drawable" << endl;
}
... render stuff in the pbuffer (hopefully) ...
|
Then I change context and render the textured quad:
if (!glXMakeContextCurrent(GLWin.dpy, GLWin.win, pbuffer, GLWin.ctx) ) {
cerr << "Could not make frame buffer the current drawable" << endl;
}
...
glCopyTexImage2D(targetTexture, 0, GL_RGB, 0, 0, 1024, 1024, 0);
glBindTexture(GL_TEXTURE_2D, targetTexture);
//glReadPixels(0, 0, 1024, 1024, GL_RGB, GL_UNSIGNED_BYTE, tmpData);
//glTexImage2D(GL_TEXTURE_2D, 0, 3, 1024, 1024, 0, GL_RGB, GL_UNSIGNED_BYTE, tmpData);
glXSwapBuffers(GLWin.dpy, GLWin.win);
|
I do use powers of 2 (1024*1024). About the caching, I tried to call glFlush (right technique?) but that didn't help.
|