Re: Help: texture mapping from pbuffer

New Message Reply Date view Thread view Subject view Author view

Phil Keslin (philk++at++cthulhu.engr.sgi.com)
Tue, 15 Dec 1998 10:53:02 -0800


Liu Xiaoyan wrote:
>
> Hi, performers,
>
> Sorry to bring up this topic again, but I do have several problems
> regarding this (a little bit long perhaps).What I'm trying to do is real
> time texture mapping with textures from pbuffer. Well, the steps I
> follow and the respective questions are:
>
> 1. define a pfTexture with attributes similar to video texturing
> {
> pfTexFormat(tex, PFTEX_IMAGE_FORMAT, PFTEX_RGB);
> pfTexFormat(tex, PFTEX_EXTERNAL_FORMAT, PFTEX_PACK_16); // 8 or 16?
>
> pfTexFormat(tex, PFTEX_INTERNAL_FORMAT, PFTEX_RGB_5);
> pfTexFormat(tex, PFTEX_SUBLOAD_FORMAT, PF_ON);
> pfTexImage(tex, NULL, 4, pwidth, pheight, 0); // 4 or 3?
> pfTexLoadImage(tex, shared->image); // main memory storing the copy
> of pbuffer image
> pfTexRepeat(tex, PFTEX_WRAP_S, PFTEX_REPEAT);
> pfTexRepeat(tex, PFTEX_WRAP_T, PFTEX_REPEAT);
> pfGStateAttr(gst, PFSTATE_TEXTURE, tex);
> }
> I'm confused by the word "component" in the man pages:
> "PFTEX_PACK_8/16 for 8-bit or 16-bit "component" packed bytes..." , does
> this component refers the same "component" as in pfTexImage(tex, NULL,
> "componet"...)? What do they refer to? My pbuffer attributes are:
> { /* Pbuffer configuration: Single buffered, with depth buffer */
> GLX_RENDER_TYPE_SGIX, GLX_RGBA_BIT_SGIX,
> GLX_DRAWABLE_TYPE_SGIX, GLX_PIXMAP_BIT_SGIX,
> GLX_RED_SIZE, 5,
> GLX_GREEN_SIZE, 5,
> GLX_BLUE_SIZE, 5,
> GLX_DEPTH_SIZE, 1,
> GLX_DOUBLEBUFFER, 0,
> GLX_STENCIL_SIZE, 0,
> None
> } so 3 color components are RGB, but the main memory to store the image
> is defined as:
> GLuint *image= pfMalloc(width * height *sizeof(GLuint), arena), 4 bytes,
> thus the component is 4?

The attributes that you have defined describe a 16bit texel or pixel
with 5 bits allocated to each of the red, green and blue components and
a single bit to the alpha component. The component parameter defines the
number of components. In this case, that is 4 (red, green, blue, and
alpha). The storage required to hold these pixels is
width*height*sizeof(short). You will overallocate in your example.

BTW, don't use PIXMAP to define a pbuffer. The correct drawable type is
GLX_PBUFFER_BIT_SGIX.

>
> 2. to get pbuffer rendering work, loading image into main memory using
> glReadPixles in the DRAW process as below:
> void updateImage(void)
> {
> dsp = pfGetCurWSConnection();
> read = pfGetPWinWSDrawable(shared->pwPbuf);
> ctx = pfGetPWinGLCxt(shared->pwPbuf);
> glXMakeCurrent(dsp, read, ctx);
> glPixelStorei(GL_PACK_ALIGNMENT, 2); // 1 or 2 ?
> glReadPixels(0, 0, pwidth, pheight, GL_RGB, GL_UNSIGNED_INT,
> shared->image);
> }
> what alignment and packing should I use in order to be consistent with
> the settings above for pfTexture? I only got garbage image.

When you read your pixels, you should only read the pixels in the
required type. You are using 6x the bandwidth requirement for reading
from the pipe by requesting and UNSIGNED_INT from the pipe.
Additionally, you are overflowing you data region. Each component read
from the pipe is an unsigned int making for a 12 byte pixel.

The following should work (assuming the contents of the pbuffer are
valid).

glPixelStorei(GL_PACK_ALIGNMENT, 2);
glReadPixels(0, 0, pwidth, pheight, GL_RGB,
GL_UNSIGNED_SHORT_5_5_5_1_EXT,
        share->image);

It is also possible to copy the contents of the pbuffer directly to the
texture.

glCopyTexSubImage2DEXT(GL_TEXTURE_2D, 0, 0, 0, 0, 0, pwidth, pheight);

This assumes that the texture is bound and the context for the pbuffer
is current and the ReadBuffer is set correctly.

> 3. Also in the DRAW process, call pfLoadTex to page in new buffer
> images:
> { pfLoadTex(tex);
> pfApplyTex(tex);
> pfClearChan(chan);
> pfDraw();
> }
> But I cannot see the new buffer being texture mapped onto the geometry.
> What's going wrong in these steps?

Your readback format doesn't match your texture format.

> 4. Since I'm paging texture from a pbuffer, I tried:
> pfTexLoadMode(tex, PFTEX_LOAD_SOURCE, PFTEX_SOURCE_FRAMEBUFFER);
> the program hangs for a few seconds and I get logged out! Why there are
> no options to specify which framebuffer to be used as Source? Is it
> possible to set a pbuffer as source for texture subloading? If yes, I
> can jump over copying from pbuffer to main memory.

make current to the pbuffer
bind the texture
copytexsubimage2dext to the texture

I can't recall the Performer nomenclature for these, but someone else
might.

> 5. What's the difference between pfTexture::Load() and Subload()? which
> one works for this kind of dynamically changing texture?

Subload.

> 6.I also got this message, what does it tell me?
>
> PF Warning/Usage: pfGetVClock() not supported for this
> context.
> PF Fatal/Internal: Assertion failed: gotNewFrame ==
> (currentCullDrawBuffer!=prevCullDrawBuffer || frameCount == 0) in
> ../../../lib/libpf/pfProcess.C at line 6700

Don't know. Someone else might though.

- Phil

-- 
Phil Keslin <philk++at++engr.sgi.com>

New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Tue Dec 15 1998 - 10:53:06 PST

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.