I have a 2D array of floats (in this case it represents a 256 color palette with RGB values)
static float[][] glColorPaletteArray = new float[256][3];
I fill the array and now want to pass it to GLES. How do I pass a 2D array in android? I try
GLES20.glUniform3fv(paletteLoc,256,glColorPaletteArray,0);
but it complains about expecting a 1D array (found float[][] expecting float[]).
The shader is expecting a vec3 uniform, ie
uniform vec3 palette[256];
so I need to keep the 2D array so the RGB components are separate floats.
What is the secret to getting the 2D array passed correctly to the GLES shader so I can then access the RGB values in the shader by using
int red = palette[100].r;
The short answer is: You cannot pass a 2D array to a shader.
In order to pass a 2D array to OpenGL, one has to flatten the array. This is relatively easy and can, eg, be done as follows:
static float[][] glColorPaletteArray = new float[256][3];
static float[] openglArray = new float[256*3];
for (int i = 0; i < 256; i++)
for (int j = 0; j < 3; j++)
openglArray[i * 3 + j] = glColorPalletArray[i][j];
But I would suggest that, if possible, you define the array in 1D at first hand.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.