1.material文件
不需要定义变量
2.cg文件
定义数组参数:uniform float4 arr
注意:cg中必须使用传入的数组,否则会报错。
3.主程序中更新数组信息
float m_arr[10][4];
Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName("materialName");
mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("arr", m_arr[0], 10);
关键API:
/** Sets a multiple value constant floating-point parameter to the program.
@par
Some systems only allow constants to be set on certain boundaries,
e.g. in sets of 4 values for example. The 'multiple' parameter allows
you to control that although you should only change it if you know
your chosen language supports that (at the time of writing, only
GLSL allows constants which are not a multiple of 4).
@note
This named option will only work if you are using a parameters object created
from a high-level program (HighLevelGpuProgram).
@param name The name of the parameter
@param val Pointer to the values to write
@param count The number of 'multiples' of floats to write
@param multiple The number of raw entries in each element to write,
the default is 4 so count = 1 would write 4 floats.
*/
void setNamedConstant(const String& name, const float *val, size_t count,
size_t multiple = 4);