glDrawArrays绑定到单个纹理

时间:2016-06-13 04:48:50

标签: ios opengl-es glkit

我使用GLKTextureLoader加载了许多纹理。如果我静态绑定任何加载的纹理,每个纹理都按预期工作。

但我试图绑定每个glDrawArrays调用的随机纹理,但纹理绑定始终是相同的。

GLuint vbo =  vboIDs[emitterNum];

GLKMatrix4 projectionMatrix = GLKMatrix4MakeScale(1.0f, aspectRatio, 1.0f);

glUseProgram(emitterShader[emitterNum].program);

glEnable(GL_TEXTURE_2D);
glActiveTexture (GL_TEXTURE0);
//Note: valid texture names are 0-31, but in my code I store texture names returned in an array and use them. Use arc4random here for simplicity
glBindTexture(GL_TEXTURE_2D, arc4random_uniform(31)); //use a random texture name
//glBindTexture(GL_TEXTURE_2D, 2); //If I use this line instead of the line above, it will draw texture 2, or any number I specify

glBindBuffer(GL_ARRAY_BUFFER, vbo);

glUniformMatrix4fv(emitterShader[emitterNum].uProjectionMatrix, 1, 0, projectionMatrix.m);

//I set a number of uniforms such as:
glUniform1f(emitterShader[emitterNum].uTime, timeCurrentFrame);
glUniform1i(emitterShader[emitterNum].uTexture, 0);

//I set a number of vertex arrays such as:
glEnableVertexAttribArray(emitterShader[emitterNum].aShade);
glVertexAttribPointer(emitterShader[emitterNum].aShade,                // Set pointer
                      4,                                        // four components per particle (vec4)
                      GL_FLOAT,                                 // Data is floating point type
                      GL_FALSE,                                 // No fixed point scaling
                      sizeof(Particles),                        // No gaps in data
                      (void*)(offsetof(Particles, shade)));     // Start from "shade" offset within bound buffer

GLsizei rowsToUse = emitters[emitterNum]->rows;

//Draw the arrays
glDrawArrays(GL_POINTS, 0, rowsToUse );

//Then clean up
glBindTexture(GL_TEXTURE_2D, 0);
glUseProgram(0);
glDisable(GL_TEXTURE_2D);
glBindBuffer(GL_ARRAY_BUFFER, 0);

我已经尝试将纹理调用放在各个地方,比如在glDrawArrays命令之前显示和指向的位置,但无论如何 - 我不能使它绑定到不同的纹理,除非这样做是静态的。

0 个答案:

没有答案