Community
Arnold General Rendering Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Arnold OpenGL for IPR

2 REPLIES 2
Reply
Message 1 of 3
tfurrebo
928 Views, 2 Replies

Arnold OpenGL for IPR

Currently, using OpenGL I am able to get Arnold to render interactively within a viewport. The issue is that this renders black on Linux and Mac but works perfectly fine on windows, I used the display callback driver you have provided on the website and compiled. Would you be able to share the correct OpenGL types for both Linux and Mac respectively?

I'm aware that glDrawPixels is deprecated, I will be using glTexImage2D in production, but regardless, I will need the appropriate OpenGL types to work with this.


Here is the OpenGL code that works fine on Windows:

(width, height), rect = ipr.update(width, height, data)
v = bgl.Buffer(bgl.GL_FLOAT, 4)
bgl.glGetFloatv(bgl.GL_VIEWPORT, v)
vw = v[2]
vh = v[3]
bgl.glRasterPos2f(0, vh - 1.0)
bgl.glPixelZoom(vw / width, -vh / height)
bgl.glDrawPixels(width, height, bgl.GL_RGBA, bgl.GL_UNSIGNED_BYTE,
                 bgl.Buffer(bgl.GL_BYTE, len(rect), rect))
bgl.glPixelZoom(1.0, 1.0)
bgl.glRasterPos2f(0, 0)

And here is the callback function:

def _callback(x, y, width, height, buffer, data):
            #print("+++ _callback:", x, y, width, height, ctypes.cast(buffer, ctypes.c_void_p))
            if buffer:
                try:
                    if new_data.poll():
                        arnold.AiRenderInterrupt()
                    else:
                        #print("+++ _callback: tile", x, y, width, height)
                        _buffer = ctypes.cast(buffer, ctypes.POINTER(ctypes.c_ubyte))
                        a = numpy.ctypeslib.as_array(_buffer, shape=(height, width, 4))
                        rect[y : y + height, x : x + width] = a
                        redraw_event.set()
                    return
                finally:
                    arnold.AiFree(buffer)
            elif not new_data.poll():
                return
            arnold.AiRenderAbort()
            print("+++ _callback: abort")

And here is how I call the callback function:

cb = arnold.AtDisplayCallBack(_callback)
arnold.AiNodeSetPtr(driver, "callback", cb)
Tags (2)
Labels (2)
2 REPLIES 2
Message 2 of 3
svenakelian
in reply to: tfurrebo

Hi

I'm trying to create a standalone IPR (kindof like kick) using Qt C++.

I can't find any reliable informations on how to implement the callback properly.

Here is the render() slot (qt_driver is just the provided display_driver sample):

AiBegin(AI_SESSION_INTERACTIVE);
AtNode* options = AiUniverseGetOptions();

AtNode *filter = AiNode("gaussian_filter");
AiNodeSetStr(filter, "name", "gauss_filter");


AtNode *qtdriver = AiNode("qt_driver");
AiNodeSetStr(qtdriver, "name", "qt_driver");
AtRenderUpdateCallback cb = AtRenderUpdateCallback(qtIPR);
AiNodeSetPtr(qtdriver, "callback_data", &cb);

AtArray *outputs_array = AiArrayAllocate(1, 1, AI_TYPE_STRING);
AiArraySetStr(outputs_array, 0, "RGBA RGBA gauss_filter qt_driver");
AiNodeSetArray(options, "outputs", outputs_array);

AiRenderBegin(AI_RENDER_MODE_CAMERA);

I don't know how to properly use and link the callback:

void qtIPR(uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint8_t* buffer, void* data)
{
    qDebug() << "Status:\t" << AiRenderGetStatus();
    if (buffer != nullptr)
    {
        try{
        qDebug() << "Used Memory:\t" << AiMsgUtilGetUsedMemory() / 1048576;
        qDebug() << "X:\t" << x;
        qDebug() << "Y:\t" << y;
        qDebug() << "Width:\t" << width;
        qDebug() << "Height:\t" << height;


        //qDebug() << "Buffer:\t" << buffer;
        //qDebug() << "Data:\t" << data;
    }
        catch(...){
            AiFree(buffer);
        }
    }
    else{
        qDebug() << "Width:\t" << width;
    }


}
Message 3 of 3
tfurrebo
in reply to: tfurrebo

Hmm, do you mind cleaning up the code a bit so I can see what you're looking at? Thanks.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report