Re: glTexSubImage2D only working with glTexImage2D in render loop

1,991 views
Skip to first unread message

Fabien R

unread,
Jan 4, 2013, 3:49:21 AM1/4/13
to andro...@googlegroups.com
On 02/01/2013 19:03, Mathieujofis wrote:
> Works:
>
> JNIEXPORT void JNICALL Java_blahblah_render(frame)
> {
> glGenTextures(1, &videoFrameTexture);
>
You should remove the above line from ther render loop...
> glBindTexture(GL_TEXTURE_2D, videoFrameTexture);
> glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
> glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
> glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
> glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
> glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 640, 480, 0, GL_RGB,
> GL_UNSIGNED_BYTE, NULL );
>
> glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 640, 480, GL_RGB,
> GL_UNSIGNED_BYTE, frame.ptr());
> }
>
>
Can you show the way you communicate with the shaders ?
> Does not work (with gl error 502 or 501):
>
> JNIEXPORT void JNICALL Java_blahblah_init()
> {
> glGenTextures(1, &videoFrameTexture);
> glBindTexture(GL_TEXTURE_2D, videoFrameTexture);
> glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
> glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
> glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
> glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
> glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 640, 480, 0, GL_RGB,
> GL_UNSIGNED_BYTE, NULL );
> }
>
> JNIEXPORT void JNICALL Java_blahblah_render(frame)
> {
> glBindTexture(GL_TEXTURE_2D, videoFrameTexture);
> glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 640, 480, GL_RGB,
> GL_UNSIGNED_BYTE, frame.ptr());
> }
>
>
Is it normal that you never unbind your textures ?
-
Fabien

Joel Hunter

unread,
Jan 3, 2013, 1:27:34 PM1/3/13
to andro...@googlegroups.com
I'm not sure if this is your problem but I have noticed there can be some inconsistency in the order that onSurfaceCreated() and onSurfaceChanged() get called. Depending on how you are handling surface and/or context changes, perhaps this could be your issue? The context may have changed after your glTexImage2D...?


On Wed, Jan 2, 2013 at 10:03 AM, Mathieujofis <mathie...@gmail.com> wrote:
I'm trying to update my texture with glTexSubImage2D to get a faster upload but it won't work with glTexImage2D unless they reside in the same render loop.  That is, I can't call glTexImage2D in my init() function and then update the texture with glTexSubImage2D in my render loop without getting a black screen and glerrors 501 or 502 (invalid value or invalid operation) depending on the mobile device I'm using.  I'm using OpenGL ES 2.0 and have tried on an LG Revolution and a Galaxy Tab 2.0 7".  Frames are coming in from the camera via OpenCV.

As I understand it, we only want to call glTexImage2D once and then use glTexSubImage2D for the remaining updates, so if I have both in the render loop, it's as good as just using glTexImage2D.  Has anyone encountered this or could see my issue?  I'm still new to texturing with OpenGL.

Works:

    JNIEXPORT void JNICALL Java_blahblah_render(frame)
    {
        glGenTextures(1, &videoFrameTexture);
        glBindTexture(GL_TEXTURE_2D, videoFrameTexture);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 640, 480, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL );

        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 640, 480, GL_RGB, GL_UNSIGNED_BYTE, frame.ptr());
    }
Does not work (with gl error 502 or 501):

   JNIEXPORT void JNICALL Java_blahblah_init()
    {
        glGenTextures(1, &videoFrameTexture);
        glBindTexture(GL_TEXTURE_2D, videoFrameTexture);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 640, 480, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL );
    }

   JNIEXPORT void JNICALL Java_blahblah_render(frame)
    {
        glBindTexture(GL_TEXTURE_2D, videoFrameTexture);
        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 640, 480, GL_RGB, GL_UNSIGNED_BYTE, frame.ptr());
    }


This probably goes without saying, but init() is called from onSurfaceCreated() and render is called from onDrawFrame() in my Java Renderer class.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/gesR_kjMGyIJ.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

Moshe Yakobovich

unread,
Oct 10, 2013, 3:32:59 AM10/10/13
to andro...@googlegroups.com
Hi Mathieujofis,
Did you solve this issue? If so, can you say what was the problem?

yakobom
Reply all
Reply to author
Forward
0 new messages