glTexSubImage2D: The specified operation is invalid...

Right now I’m working on porting the flocking example from the 5th edition superbible to iOS7. I’m trying to convert the texture buffers to pixel buffers (ios7 doesn’t support GL_TEXTURE_BUFFER), and I’m getting the error “The specified operation is invalid for the current OpenGL state”

if (frame_index & 1) {
    glBindBuffer(GL_PIXEL_UNPACK_BUFFER, position_tbo[0]);
    glTexSubImage2D(GL_TEXTURE_2D, 0, GL_RGB, flock_size, 1, 0, GL_RGB, GL_FLOAT, &flock_position[0]);//!The specified operation is invalid for the current OpenGL state
    glBindBuffer(GL_PIXEL_UNPACK_BUFFER, velocity_tbo[0]);
    glTexSubImage2D(GL_TEXTURE_2D, 0, GL_RGB, flock_size, 1, 0, GL_RGB, GL_FLOAT, &flock_velocity[0]);//!The specified operation is invalid for the current OpenGL state
    glBindVertexArray(render_vao[1]);
} else {
    glBindBuffer(GL_PIXEL_UNPACK_BUFFER, position_tbo[1]);
    glTexSubImage2D(GL_TEXTURE_2D, 0, GL_RGB, flock_size, 1, 0, GL_RGB, GL_FLOAT, &flock_position[1]);
    glBindBuffer(GL_PIXEL_UNPACK_BUFFER, velocity_tbo[1]);
    glTexSubImage2D(GL_TEXTURE_2D, 0, GL_RGB, flock_size, 1, 0, GL_RGB, GL_FLOAT, &flock_velocity[1]);
    glBindVertexArray(render_vao[0]);
}

The reason the height is 1 is in order to imitate GL_TEXTURE_1D which iOS doesn’t support. As far as I know, I don’t need to call glEnable(GL_TEXTURE_2D) for with ES 3.0, what might I be missing?

Cheers,
Steve

Your arguments to TexSubImage are all wrong, they look like you’re trying to use TexImage.

Also read the ES3 spec. Specifically table 3.2 “Valid combinations of format, type, and sized internalformat.”

You’ll see that floating point formats work differently than they do in an ES2 context (with OES_texture_float); you must specify a sized internalformat (in this case, RGB32F) to use floating point textures.

Khronos says ES3 is backwards-compatible with ES2. Which is mostly true, but unfortunately when they promoted many of the existing ES2 extensions into the ES3 core, they subtly changed the behavior in non-backwards compatible ways. Floating point formats are one example.

Instead of copying texel data from a transform feedback buffer, you might try reading it directly, via a UBO. You’ll have to ensure flock_size fits into the max UBO size.

[QUOTE=arekkusu;1257269]Your arguments to TexSubImage are all wrong, they look like you’re trying to use TexImage.

Also read the ES3 spec. Specifically table 3.2 “Valid combinations of format, type, and sized internalformat.”

You’ll see that floating point formats work differently than they do in an ES2 context (with OES_texture_float); you must specify a sized internalformat (in this case, RGB32F) to use floating point textures.

Khronos says ES3 is backwards-compatible with ES2. Which is mostly true, but unfortunately when they promoted many of the existing ES2 extensions into the ES3 core, they subtly changed the behavior in non-backwards compatible ways. Floating point formats are one example.

Instead of copying texel data from a transform feedback buffer, you might try reading it directly, via a UBO. You’ll have to ensure flock_size fits into the max UBO size.[/QUOTE]

A UBO looks like it would be a better way to set it up for sure :slight_smile: But what is the UBO equivalent for a sampler/texelFetch in the GLSL?