PDA

View Full Version : Optimizing PBO/VBO implementation

02-25-2010, 01:45 PM
I have a simulation that I have implemented with cuda. I've implemented a PBO as well as a VBO to visualize the data. As of now, the PBO implementation outperforms the VBO. But I'm not sure I've even implemented the VBO (or PBO) with the most optimal (or logical) configuration.

The Problem: I have a 2D float array with values between 0.0 and 1.0. I would like to visualize this 2D array where each index value in the array is a color.

Before I go on about my current implementations, I'd like to ask the gurus... what kind of PBO/VBO solution would you implement and why?

Logically I would think a vbo, where the data is a color index array. But I have yet to find any examples of this...

Alfonse Reinheart
02-25-2010, 01:54 PM
The Problem: I have a 2D float array with values between 0.0 and 1.0. I would like to visualize this 2D array where each index value in the array is a color.

What do you mean by this? If your colors are floating-point values, then how do you convert them into indexes? Indexes into what?

02-25-2010, 02:15 PM
How do I take a matrix, that stores floating point values, and visualize those values with OpenGL.

Pretend this is a sold surface, where at each point (or index) on the surface there is a value. How do I visualize the values as colors?
__ __ __
|__|__|__|
|__|__|__|
|__|__|__|

Think of a rectangular polygon with varying colors.

My first implementation was to create a pbo the same size as my matrix, and store colors to represent each corresponding point (or index) of my matrix. I would then bind my pbo to a texture and render it to a quad.

My second implementation was a vbo, where I stored static vertex points corresponding to each point (or index) of my matrix, and a color array to represent the color of each vertex. I modify the colors in the color array to change with the simulation.

Now I'm curious if there is a way to simply use my matrix data as the data in my pbo/vbo, and render those values as colors. Instead of having to create separate representations. I'm sorry if this is very confusing...

Alfonse Reinheart
02-25-2010, 02:56 PM
I would then bind my pbo to a texture and render it to a quad.

Is this a buffer texture, or are you uploading data from the buffer object to the texture?

Now I'm curious if there is a way to simply use my matrix data as the data in my pbo/vbo, and render those values as colors.

It depends. What is the mapping between a floating-point value and a color? Is it something you can code into GLSL?

02-25-2010, 04:03 PM
Is this a buffer texture, or are you uploading data from the buffer object to the texture?

I'm uploading data from the pbo to the texture.

It depends. What is the mapping between a floating-point value and a color? Is it something you can code into GLSL?

I'm not sure. The red book discusses color-index-mode instead of RGBA mode, but highly recommends RGBA whenever possible.

Some options that seem like they would work:

1) instead of using GL_ARRAY_BUFFER (vbo) or GL_PIXEL_UNPACK_BUFFER (pbo), use GL_ELEMENT_ARRAY_BUFFER.

Then instead of Rendering with:
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_POINTS...);

Render with:
glEnableClientState(GL_INDEX_ARRAY);
glDrawElements(GL_POINTS...);

...something along those lines.

I honestly haven't looked into any GLSL.

Alfonse Reinheart
02-25-2010, 04:25 PM
I'm not sure.

How can you not know? This is something you said you were already doing. You said that, for each floating-point value, you convert it into a color. All I'm asking is how you do that.

02-25-2010, 04:40 PM
Apologize, I misinterpreted your question as how can I do it, opposed to how am I currently doing it... Long days... long nights...

I traverse my matrix array, and I pass each value to a function that converts that to a color:

__device__ void make_color5( float4 *color, float val )
{
float red=0.0, green=0.0, blue=0.0;

if( val > 0.9f ) { red = 1.0; green = 0.0; blue = 0.0; } //red
else if( val > 0.8){ red = 1.0; green = .64; blue = 0.0; } //orange
else if( val > 0.7){ red = 1.0; green = 0.78; blue = 0.0; }
else if( val > 0.6){ red = 1.0; green = 1.0; blue = 0.0; } // yellow
else if( val > 0.5){ red = 0.4; green = 1.0; blue = 0.2; } //green
else if( val > 0.4){ red = 0.4; green = 0.98; blue = 0.6; }
else if( val > 0.3){ red = 0.0; green = 0.8; blue = 0.8; }
else if( val > 0.2){ red = 0.0; green = 0.39; blue = 1.0; }
else if( val > 0.1){ red = 0.0; green = 0.0; blue = 1.0; }
else { red = 0.0; green = 0.098; blue = 0.59; }

color[0].x = red;
color[0].y = green;
color[0].z = blue;
}

that color is stored into my PBO/VBO

Alfonse Reinheart
02-25-2010, 05:55 PM
So you multiply the float * 10, turn it into an integer, and perform a lookup in a table. You can code that in GLSL just fine, either in the vertex shader (where you use a generic vertex attribute to pass in your data) or in the fragment shader (where you sample from a texture).