will mi
unread,May 14, 2010, 3:55:35 AM5/14/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to G3D Users
I try to use renderbuffer instead of Texture to do off-screen
rendering.
While use Texture get the right result, but renderbuffer get a error
when use glReadPixels to read data of renderbuffer back to CPU.
The error is that "access violation writing location" .
I have malloc enough memory on CPU, and glGetTexImage works fine while
using Texture.
The funciotn of Texture, toImage3() gives me right Image, too.
So, how to use renderbuffer?( as I use rendering result on CPU, so
it's better to use renderbuffer, rather than Texture for me)
I use G3D-8.00-b1, Windows7, and GPU is NVIDIA GT240M.
following is main code of framebuffer.
My define:
FrameBuffer::Ref framebuffer;
Texture::Ref outColorTex;
Texture::Ref outColorTex2;
Renderbuffer::Ref renb;
Renderbuffer::Ref renb2;
init:
framebuffer = Framebuffer::create("framebuffer");
outColorTex = Texture::createEmpty("outColorTex", 1024, 1024,
ImageFormat::RGBA16());
outColorTex2 = Texture::createEmpty("outColorTex", 1024, 1024,
ImageFormat::RGBA16());
renb = RenderBuffer::createEmpty("renderbuffer", 1024, 1024,
ImageFormat::RGBA16F());
renb2 = RenderBuffer::createEmpty("renderbuffer2", 1024, 1024,
ImageFormat::RGBA16F());
framebuffer->set(FrameBuffer::COLOR_ATTACHMENT0, outColorTex);
framebuffer->set(Framebuffer::COLOR_ATTACHMENT1, outColorTex2);
//framebuffer->set(FrameBuffer::COLOR_ATTACHMENT0, renb);
//framebuffer->set(Framebuffer::COLOR_ATTACHMENT1, renb2);
render:
rd->pushState(framebuffer);
rd->push2D();
// Enable the shader
configureShaderArgs(localLighting);
//link a shader here and it will write gl_FragData[0]
and gl_FragData[1]
rd->setShader(testShader);
// Send model geometry to the graphics card
Draw::rect2D( framebuffer->rect2DBounds(), rd, Color3::green() );
float* cpuImage1 = new float[framebuffer->width() * framebuffer-
>height()];
float* cpuImage2 = new float[framebuffer->width() * framebuffer-
>height()];
glReadBuffer( GL_COLOR_ATTACHMENT0_EXT );
glReadPixels(0, 0, framebuffer->width(), framebuffer->height(),
GL_RGBA, GL_FLOAT, (GLvoid*)cpuImage1);
//glGetTexImage(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, GL_FLOAT,
cpuImage1);
delete[] cpuImage1;
delete[] cpuImage2;
rd->pop2D();
rd->popState();