Skip to content

Click Buffer

theproadam edited this page Apr 24, 2020 · 3 revisions

To enable clickable objects, renderXF provides a click buffer solution that make its possible to retrieve a face index and a custom integer for each pixel on the screen.

Initializing or deinitializing the click buffer

To initialize/deinitialize the click buffer, use the InitializeClickBuffer()/DeinitializeClickBuffer() function from the renderX instance:

//Initializes The Click Buffer:
GL.InitializeClickBuffer();

//Deinitializes The Click Buffer:
GL.DeinitializeClickBuffer();     

Toggling the click buffer

The click buffer can be toggled on and off, through the SetClickBufferWrite() function from the renderX instance. This is useful for rendering some objects that need to be clickable, but others that do not.

//Enables The Click Buffer Write:
GL.SetClickBufferWrite(true);

//Disables The Click Buffer Write:
GL.SetClickBufferWrite(false);

Setting the custom integer

To set a custom integer value, (ie. different objects have different values) use the SetClickBufferWrite() function to set its data.

GL.SetClickBufferInt(myInt);

It is also possible to store separate data via bitwise operations.

Retrieving click buffer data

To retrieve the click buffer data, use the GetClickBufferData() function from the renderX instance. Please note that GetClickBufferData() will return false if the requested coordinates are not inside the view buffer, or the selected pixel has no click buffer data applied to it.

int FaceIndex;
int RetrievedInteger;

if (GL.GetClickBufferData(srcX, srcY, out FaceIndex, out RetrievedInteger))
{
    //Do Something
}

Clearing the click buffer

To clear the click buffer after everyframe, just use the ClearClearBuffer() function from the renderX instance.

GL.ClearClickBuffer();
Click buffers can be also created manually with the fragment shader, however the performance will be a lot slower.
Please note that not every rendering mode supports the click buffer
Clone this wiki locally