I’m trying to apply a video file as a texture in OpenGL ES on iOS 5.0+ using CVOpenGLESTextureCache.
I’ve found Apple’s RosyWriter sample code, and have been reading through it.
The question I have is:
How are the textures finally being delivered to the uniforms in the fragment shader?
In the RosyWriterPreviewView class, I follow it all the way up to
glBindTexture(CVOpenGLESTextureGetTarget(texture),
CVOpenGLESTextureGetName(texture))
after which some texture parameters are specified.
However, I don’t see the texture uniform (sampler2D videoframe) ever being explicitly referenced by the sample code. The texture-sending code I’ve become used to would look something like:
GLint uniform = glGetUniformLocation(program, "u_uniformName");
with a subsequent call to actually send the texture to the uniform:
glUniform1i(GLint location, GLint x);
So I know that SOMEhow RosyWriter is delivering the texture to the uniform in its fragment shader, but I can’t see how and where it’s happening.
In fact, the sample code includes the comment where it builds up the OpenGL program:
// we don't need to get uniform locations in this example
Any help on why this is & how the texture is getting sent over would be great.
In the RosyWriter example, I think the reason they’re able to get away without using
glUniformi()at any point for thevideoframeuniform is that they’re binding the input texture to texture unit 0.When specifying a uniform value for a texture, the value you use is the texture unit that texture is bound to. If you don’t set a value for a uniform, I believe it should default to 0, so by binding the texture to unit 0 always they never have to set a value for the
videoframeuniform. It will still pull in the texture attached to unit 0.