繁体   English   中英

如何将变量(非均匀)浮点值从C ++传递到顶点着色器OpenGL ES 2.0

[英]How pass a variable ( not uniform) float value from c++ to a vertex shader OpenGL ES 2.0

我如何从c ++发送倾倒着色器值,我知道我可以使用统一类型,但这无效,因为有必要修改每个顶点中的值并且统一是常数,我已经知道那里是一种``输入''和``输出''但不支持OpenGL ES 2.0的示例,您向我发送了一个示例如何将这些值传递给顶点着色器浮点,我将它们发送给我使用的部分代码。

attribute float cppValue;
varying float valueV;

void main ()
{
valueV= cppValue;
}

exampleValueCpp float = 1;
glVertexAttribPointer (0, 1, GL_FLOAT, GL_FALSE, 0, & exampleValueCpp);

我已经看到有一个函数“ glVertexAttrib1f”和“ glVertexAttrib1fv”来修改属性,但是我认为它只能与glBegin和glEnd一起使用,并且这些函数在OpenGLES 2.0或更高版本中已经过时了,对吗? Asher可能发送一个不恒定的顶点着色器值?

如果您希望每个顶点的浮点数都不同,则应该有一个数组来收集它们:

float* exampleValueCpp = new float[numVertex];
for(int i = 0;i<numVertex;i++){
    //fill values
}
glBindBuffer(GL_ARRAY_BUFFER,0);//use application memory
glVertexAttribPointer (0, 1, GL_FLOAT, GL_FALSE, 0, exampleValueCpp);

但是,您也可以将其上传到VBO并像这样使用:

glGenBuffers(1, &cppBuffer);
glBindBuffer(GL_ARRAY_BUFFER, cppBuffer);

float* exampleValueCpp = new float[numVertex];
for(int i = 0;i<numVertex;i++){
    //fill values
}

glBufferData(GL_ARRAY_BUFFER, numVertex*sizeof(float), exampleValueCpp, GL_STATIC_DRAW);
delete[] exampleValueCpp;
glVertexAttribPointer (0, 1, GL_FLOAT, GL_FALSE, 0, 0);//last parameter is offset into the buffer

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM