How can I pass 2D array or 1D array as parameters to shader


#1

Hi there,

How can I pass 2D array or 1D array as parameters to shader?
I want to know if I could use UBO or texture to do this.
And, how can declare these stuff in fragment shader?

I have search a lot of resources but nothing, hope someone can help me.

Thanks a lot.

ex:

float *p = new float[arraysize];

or

int p1[][];
int p2[];


#2

Here is excerpt from ofShader.h

	// set an array of uniform values
	void setUniform1iv(const string & name, const int* v, int count = 1) const;
	void setUniform2iv(const string & name, const int* v, int count = 1) const;
	void setUniform3iv(const string & name, const int* v, int count = 1) const;
	void setUniform4iv(const string & name, const int* v, int count = 1) const;

	void setUniform1fv(const string & name, const float* v, int count = 1) const;
	void setUniform2fv(const string & name, const float* v, int count = 1) const;
	void setUniform3fv(const string & name, const float* v, int count = 1) const;
	void setUniform4fv(const string & name, const float* v, int count = 1) const;

Or you can send data as texture data if you want to send large data.

	// set a texture reference
	void setUniformTexture(const string & name, const ofBaseHasTexture& img, int textureLocation) const;
	void setUniformTexture(const string & name, const ofTexture& img, int textureLocation) const;
	void setUniformTexture(const string & name, int textureTarget, GLint textureID, int textureLocation) const;