How to update Texture?

30 views
Skip to first unread message

Xana Hopper

unread,
May 18, 2013, 9:08:57 AM5/18/13
to g3d-...@googlegroups.com
Now I'm generate some pixels in per frame and upload it to Texture which is already created.


unsigned short * data;
shared_ptr<GLPixelTransferBuffer> TBuffer = PackedNoise->toPixelTransferBuffer();
data = (unsigned short *)(TBuffer->mapReadWrite());
int offset = t * NPackSizeSq;
for(int i = 0; i < NPackSizeSq; ++i)
{
data[i] = 32768 + PackedNoisePtr[i + offset]; //Here PackedNoisePtr is a pointer to int;
}
TBuffer->unmap();
TBuffer->bindRead();
//This place should be glTexSubIImage2D that Texture::update use to upload data to GPU but I
//don't know how to do it. Like this?
//glTexSubImage2D(PackedNoise->openGLTextureTarget(), 0, 0, 0, PackedNoise->width(), PackedNoise->height(), PackedNoise->format()->openGLBaseFormat, PackedNoise->format()->openGLDataFormat, 0);
//Or just do something to update it from Image1\Image3\Image4. I found that GLPixelTransferBuffer can just be convert to Image class but it doesn't work.
TBuffer->unbindRead();

Morgan McGuire

unread,
May 18, 2013, 10:55:19 AM5/18/13
to g3d-...@googlegroups.com
To update a texture...call Texture::update()

-m

Prof. Morgan McGuire
Computer Science Department
Williams College
http://cs.williams.edu/~morgan


--
You received this message because you are subscribed to the Google Groups "G3D Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to g3d-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Xana Hopper

unread,
May 18, 2013, 8:41:50 PM5/18/13
to g3d-...@googlegroups.com
I found Texture::update() method. But I don't know how to use it. I modifed Texture by using Texture::toPixelTransferBuffer(). the update method require a ImageRef
that I don't know how to convert GLPixelTransferBuffer to any of Image1\Image3\Image4...

在 2013年5月18日星期六UTC+8下午10时55分19秒,Morgan McGuire写道:

Morgan McGuire

unread,
May 18, 2013, 9:15:15 PM5/18/13
to g3d-...@googlegroups.com
Image1/3/4 are deprecated--use Image instead.

-m

Prof. Morgan McGuire
Computer Science Department
Williams College
http://cs.williams.edu/~morgan


Xana Hopper

unread,
May 19, 2013, 5:48:18 AM5/19/13
to g3d-...@googlegroups.com
But update mathod needs getCArray() and Image doesn't have it.

在 2013年5月19日星期日UTC+8上午9时15分15秒,Morgan McGuire写道:

Michael Mara

unread,
May 19, 2013, 10:01:47 AM5/19/13
to g3d-...@googlegroups.com
This is the Texture::update code from the latest svn revision (it must have got put in right after the 9.00 beta 4 release...)

void Texture::update(const shared_ptr<PixelTransferBuffer>& src, int mipLevel, CubeFace face) {
    alwaysAssertM(format()->openGLBaseFormat == src->format()->openGLBaseFormat,
                    "Data must have the same number of channels as the texture: this = " + format()->name() + 
                    "  src = " + src->format()->name());

    const shared_ptr<GLPixelTransferBuffer>& glsrc = dynamic_pointer_cast<GLPixelTransferBuffer>(src);

    glPushAttrib(GL_TEXTURE_BIT);
    {
        glBindTexture(openGLTextureTarget(), openGLID());
        glPixelStorei(GL_PACK_ALIGNMENT, 1);
            
        const GLint xoffset = 0;
        const GLint yoffset = 0;
            
        GLenum target = openGLTextureTarget();
        if (isCubeMap()) {
            target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + (int)face;
        }

        const void* ptr = NULL;

        if (notNull(glsrc)) {
            // Bind directly instead of invoking bindRead(); see below for discussion
            glBindBuffer(GL_PIXEL_UNPACK_BUFFER, glsrc->glBufferID());

            // The pointer is an offset in this case
            ptr = 0;
        } else {
            // Regular path
            ptr = src->mapRead();
        }
            
        glTexSubImage2D
            (target, 
                mipLevel,
                xoffset,
                yoffset,
                src->width(), 
                src->height(), 
                src->format()->openGLBaseFormat,
                src->format()->openGLDataFormat, 
                ptr);

        if (notNull(glsrc)) {
            // Creating the fence for this operation is VERY expensive because it causes a pipeline stall [on NVIDIA GPUs],
            // so we directly unbind the buffer instead of creating a fence.
            glBindBuffer(GL_PIXEL_UNPACK_BUFFER, GL_NONE);
        } else {
            // We mapped the non-GL PTB, so unmap it 
            src->unmap();
        }
    }
    glPopAttrib();
}

Gmail

unread,
May 20, 2013, 7:17:45 AM5/20/13
to g3d-...@googlegroups.com
Thanks a lot and may I ask when could we get G3D v9.0 Release ?

----------
Xana Hopper
NAEI
Yantai, Shandong, China
Reply all
Reply to author
Forward
0 new messages