glTexImage2D simply *is* slow. Moving stuff from system memory to texture memory simply takes time and usually requires copying stuff around more than just the obvious traffic through the bus.
In your case, though, I think you could optimize your problem and cut some glTexImage2D calls by combining your textures into one (since they are GL_LUMINANCE format of GL_UNSIGNED_BYTE type). From a private email, you told me that you are trying to update these textures in real-time from a video camera. I can't tell from your code where the data sent in textures to the GPU comes from or what you do with it prior to sending it as a texture; but I would consider using one common buffer for everything, with all the elements interlaced. That way you cut your calls to glTexImage2D (and all other texture related OpenGL ES calls) from 3 to 1 per frame. One other thing: the suggestion I gave you in another thread was more of a listing of things to try, and not "the answer". In general, pretty much all high-end Android phones still tend to be somewhat fragment-shader-limited (in terms of performance). If we were talking about desktop GPUs, then for certain doing the YUV transformation in the fragment shader would be the way to go; it's not so clear in a mobile platform. I would certainly profile and find out what specific bottlenecks I am facing (which, in your case, might be the repeated calls to glTexImage2D) Good luck! On Nov 8, 1:48 am, 袁堂夫 <[email protected]> wrote: > when draw YUV frame use opengl 2.0 and shader on nexus one,but the > function glTexImage2D is too slow ,cost 40-60 ms > who can fix it ? the key codes: > ------------------------------------------------- > > int CreateSimpleTexture2D() > { > int err, i; > > for (i=0; i<3;i++) > { > glGenTextures(1, &userData.textureId[i]); > if (err = glGetError()) { > // NSLog(@"Error: Could not generate texture: > %d", err); > > __android_log_print(ANDROID_LOG_ERROR,"CreateSimpleTexture2D","Error: > Could not generate texture: %d", err); > return 0; > } > > glBindTexture(GL_TEXTURE_2D, userData.textureId[i]); > if (err = glGetError()) { > // NSLog(@"Error: Could not bind texture: %d", > err); > > __android_log_print(ANDROID_LOG_ERROR,"CreateSimpleTexture2D","Error: > Could not bind texture: %d", err); > return 0; > } > } > > glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, > GL_LINEAR); > if (err = glGetError()) { > //NSLog(@"Error: Could not set texture minimization > filter: %d", err); > > __android_log_print(ANDROID_LOG_ERROR,"CreateSimpleTexture2D","Error: > Could not set texture minimization filter: %d", err); > return 0; > } > > glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, > GL_LINEAR); > if (err = glGetError()) { > // NSLog(@"Error: Could not set texture magnification > filter: %d", err); > > __android_log_print(ANDROID_LOG_ERROR,"CreateSimpleTexture2D","Error: > Could not set texture magnification filter: %d", err); > return 0; > } > > glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, > GL_CLAMP_TO_EDGE); > glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, > GL_CLAMP_TO_EDGE); > glGenerateMipmap(GL_TEXTURE_2D); > return 1; > } > > ---------------------------------------render frame > ------------------------------------------------- > glViewport ( 0, 0, g_WindowsWidth, g_WindowsHeight ); > checkGlError("glViewport"); > //glDrawBuffer(GL_COLOR_ATTACHMENT0); > // Clear the color buffer > glClear ( GL_COLOR_BUFFER_BIT ); > checkGlError("glClear"); > // Use the program object > glUseProgram ( userData.programObject ); > checkGlError("glUseProgram"); > // Load the vertex position > glVertexAttribPointer ( userData.positionLoc, 3, GL_FLOAT, > GL_FALSE, 5 * > sizeof(GLfloat), vVertices ); > // Load the texture coordinate > glVertexAttribPointer ( userData.texCoordLoc, 2, GL_FLOAT, > GL_FALSE, 5 * > sizeof(GLfloat), &vVertices[3] ); > > glEnableVertexAttribArray ( userData.positionLoc ); > glEnableVertexAttribArray ( userData.texCoordLoc ); > > long long ttttttt=av_gettime(); > // Bind the texture > glActiveTexture ( GL_TEXTURE1 ); > glBindTexture ( GL_TEXTURE_2D, userData.textureId[1] ); > glUniform1i ( userData.samplerLocU, 1); > > glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); > > glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); > glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, > GL_CLAMP_TO_EDGE); > glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, > GL_CLAMP_TO_EDGE); > //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, > GL_REPEAT); > //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, > GL_REPEAT); > //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); > > //glPixelStorei(GL_UNPACK_ALIGNMENT,1); > > glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width/2, > height/2, 0, > GL_LUMINANCE, GL_UNSIGNED_BYTE, pict->data[1]); > checkGlError("glTexImage2D....pict->data[1]"); > //glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width*0.5, > height*0.5, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, pict->data[1]); > > // Bind the texture > glActiveTexture ( GL_TEXTURE2 ); > glBindTexture ( GL_TEXTURE_2D, userData.textureId[2] ); > glUniform1i ( userData.samplerLocV, 2); > > glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); > > glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); > glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, > GL_CLAMP_TO_EDGE); > glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, > GL_CLAMP_TO_EDGE); > //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, > GL_REPEAT); > //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, > GL_REPEAT); > //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); > //glPixelStorei(GL_UNPACK_ALIGNMENT,1); > > glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE,width/2, > height/2, 0, > GL_LUMINANCE, GL_UNSIGNED_BYTE, pict->data[2]); > > checkGlError("glTexImage2D....pict->data[2]"); > // Set the sampler texture unit to 0 > glActiveTexture ( GL_TEXTURE0 ); > glBindTexture ( GL_TEXTURE_2D, userData.textureId[0] ); > glUniform1i ( userData.samplerLocY, 0); > > glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); > > glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); > glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, > GL_CLAMP_TO_EDGE); > glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, > GL_CLAMP_TO_EDGE); > //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, > GL_REPEAT); > //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, > GL_REPEAT); > //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); > //glPixelStorei(GL_UNPACK_ALIGNMENT,1); > > glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0, > GL_LUMINANCE, GL_UNSIGNED_BYTE, pict->data[0]); > > __android_log_print(ANDROID_LOG_ERROR,"GPU","%lld",(av_gettime()-ttttttt)/1000); > checkGlError("glTexImage2D....pict->data[0]"); > glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices > ); -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

