Hello Guest

[SOLVED] PBO pack -> unpack operations on stencil planes

  • 1 Replies
  • 3175 Views
[SOLVED] PBO pack -> unpack operations on stencil planes
« on: December 13, 2011, 18:00:26 »
Hello, I'm trying to make use of the PBO (pixel object buffer, not PBuffer) to make rendering a pattern (a console logging event) better. But the unpacked pbo will not render correctly.
I managed to pack() a stencil plane where it's drawn the pattern of some GLdrawString(x,y,str) calls on an area named ROI (a Rectangle.bounds). I use ARBPixelBufferObject.*.
Code: [Select]
/*
     * {@link GLHandler.ext#PixelBufferObjects} must be available
     *
     */

    public void unpack() {
        assert _pboItemR().data.capacity() == _pboItemW().data.capacity() : "bytes size are different on read and write buffers. Pack() first before to unpack!";
        if (!ROI().isEmpty()) {
            /** "decals" pattern drawing */
            GL11.glPushAttrib(GL11.GL_STENCIL_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_COLOR_BUFFER_BIT);
            GL11.glDisable(GL11.GL_DEPTH_TEST);
            GL11.glColorMask(false, false, false, false);
            GL11.glEnable(GL11.GL_STENCIL_TEST);
            GL11.glStencilFunc(GL11.GL_ALWAYS, 1, 1);
            GL11.glStencilOp(GL11.GL_REPLACE, GL11.GL_REPLACE, GL11.GL_REPLACE);
            GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
            ARBPixelBufferObject.glBindBufferARB(ARBPixelBufferObject.GL_PIXEL_UNPACK_BUFFER_ARB, pboBufferW());
            if ((bstate & DIRTY) != 0) {
                ARBPixelBufferObject.glBindBufferARB(ARBPixelBufferObject.GL_PIXEL_PACK_BUFFER_ARB, pboBufferR());
                /** copy to the bytebuffer
                length - the length of the mapped memory in bytes.
                old_buffer - A ByteBuffer. If this argument points to the same address and has the same capacity as the new mapping, it will be returned and no new buffer will be created.*/
                _pboItemR().data = ARBPixelBufferObject.glMapBufferARB(ARBPixelBufferObject.GL_PIXEL_PACK_BUFFER_ARB, ARBPixelBufferObject.GL_READ_ONLY_ARB, null);
                if (_pboItemR().data == null) {
                    if (DebugMap._getInstance().isDebugLevelEnabled(RenderingScene.DBUG_RENDER)) {
                        System.err.println(JXAenvUtils._JXAEnvOutput(StencilPBO.class.getSimpleName() + " : no pbobuffer read !!!", JXAenvUtils.SYS_ERROR));
                    }
                    _pboItemR().data = BufferIO._new(0);
                } else {
                    if (DebugMap._getInstance().isDebugLevelEnabled(RenderingScene.DBUG_RENDER)) {
                        System.out.println("found a packed pbobuffer of " + FileUtils.byteCountToDisplaySize(_pboItemR().data.capacity()));
                    }
                }
                _pboItemW().data = new BufferIO<ByteBuffer>(_pboItemR().data).getData();

                ARBPixelBufferObject.glBufferDataARB(ARBPixelBufferObject.GL_PIXEL_UNPACK_BUFFER_ARB, _pboItemW().data, ARBPixelBufferObject.GL_STREAM_DRAW_ARB);
                ARBPixelBufferObject.glUnmapBufferARB(ARBPixelBufferObject.GL_PIXEL_PACK_BUFFER_ARB);
                ARBPixelBufferObject.glBindBufferARB(ARBPixelBufferObject.GL_PIXEL_PACK_BUFFER_ARB, 0);
                bstate = PACKED;
            }
            if ((bstate & CLEARED) == 0) {
                if (DebugMap._getInstance().isDebugLevelEnabled(RenderingScene.DBUG_RENDER)) {
                    System.out.println("Unpacked Buffer " + FileUtils.byteCountToDisplaySize(GL15.glGetBufferParameter(ARBPixelBufferObject.GL_PIXEL_UNPACK_BUFFER_ARB, ARBPixelBufferObject.GL_BUFFER_SIZE_ARB)));
                }
                GLHandler._transformBegin(ROI, z, transform, scaleArgs, translateArgs, rotateArgs);
                /** draw stored pbo stencil */
                /** project depth bounds */
                float scaleX = Math.round(ROI.width / ROIpack.width), scaleY = Math.round(ROI.height / ROIpack.height);
                /** set rasterpos, and pixel scale*/
                GL11.glPixelZoom(scaleX, scaleY);
                GL11.glDrawPixels(ROIpack.width, ROIpack.height, GL11.GL_STENCIL_INDEX, GL11.GL_BITMAP, 0);
                GL11.glPixelZoom(1, 1);
                GLHandler._transformEnd();
            }
            ARBPixelBufferObject.glBindBufferARB(ARBPixelBufferObject.GL_PIXEL_UNPACK_BUFFER_ARB, 0);
            GL11.glPopAttrib();
        }
    }[/tt]

I find this output in System.out :
Quote
found a packed pbobuffer of 600 bytes
Unpacked Buffer 600 bytes
found a packed pbobuffer of 54 bytes
Unpacked Buffer 54 bytes
found a packed pbobuffer of 72 bytes
Unpacked Buffer 72 bytes
found a packed pbobuffer of 72 bytes
Unpacked Buffer 72 bytes
found a packed pbobuffer of 176 KB
Unpacked Buffer 176 KB
found a packed pbobuffer of 176 KB
Unpacked Buffer 176 KB
found a packed pbobuffer of 1004 bytes
Unpacked Buffer 1004 bytes

But unpack operation looks weird see attached snapshot below (target layout is Capturepbo1 and when using pbo Capturepbo2) !!

« Last Edit: December 15, 2011, 06:04:51 by broumbroum »

Re: PBO pack -> unpack operations on stencil planes
« Reply #1 on: December 15, 2011, 06:04:31 »
 :D
I had to pack and unpack with GL_FLOAT .... and also used glWindowPos to position the rasterPos for drawPixels. seems that rasterPos is not updated correctly by glRasterPos and modelview etc.
Code: [Select]
pack() {
// gluPROJECT ROI(bounds Rectangle)
            GL11.glGetInteger(GL11.GL_VIEWPORT, viewport);
            Project.gluProject(ROI.x, ROI.y, z, mView = _GLgetTopOftheStackMX(GL11.GL_MODELVIEW_MATRIX), mProj = _GLgetTopOftheStackMX(GL11.GL_PROJECTION_MATRIX), viewport, pos);
            int x = Math.round(pos.get()), y = Math.round(pos.get());
            viewport.rewind();
            pos.rewind();
            Project.gluProject((float) ROI.getMaxX(), (float) ROI.getMaxY(), z, mView, mProj, viewport, pos);
            /** window coordinates !*/
            ROIpack.setFrameFromDiagonal(x, y, pos.get(), pos.get());
...
GL11.glReadPixels(ROIpack.x, ROIpack.y, ROIpack.width, ROIpack.height, GL11.GL_STENCIL_INDEX, GL11.GL_FLOAT, 0);}
unpack() {...
GL14.glWindowPos3d(ROIpack.x, ROIpack.y, z);
GL11.glDrawPixels(ROIpack.width, ROIpack.height, GL11.GL_STENCIL_INDEX, GL11.GL_FLOAT, 0);}
« Last Edit: December 15, 2011, 07:45:08 by broumbroum »