question

Tyler Furreboe avatar image
Tyler Furreboe asked ·

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)
renderopengl
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Tyler Furreboe avatar image
Tyler Furreboe answered ·

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

Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Sven Akelian avatar image
Sven Akelian answered ·

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;
    }


}
Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Welcome to the Arnold Answers community.

This is the place for Arnold renderer users everywhere to ask and answer rendering questions, and share knowledge about using Arnold, Arnold plugins, workflows and developing tools with Arnold.

If you are a new user to Arnold Answers, please first check out our FAQ and User Guide for more information.

When posting questions, please be sure to select the appropriate Space for your Arnold plugin and include the plugin version you are using.

Please include images, scene and log files whenever possible as this helps the community answer your questions.

Instructions for generating full verbosity log files are available for MtoA, MaxtoA, C4DtoA, HtoA, KtoA, and Kick.

If you are looking for Arnold Documentation and Support please visit the Arnold Support site.

To try Arnold please visit the Arnold Trial page.

Bottom No panel present for this section.