Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Texture updates not appearing for 1 frame?

  1. #1
    Newbie Newbie
    Join Date
    May 2018
    Posts
    1

    Texture updates not appearing for 1 frame?

    I have a texture - a sprite sheet, really, that gets updated over time periodically (not every frame), and then those updated portions are drawn in the same frame. When this happens, I frequently see one frame of garbage for the updated sprites, where I think the texture's old data is displayed instead of the new data. This is not a question about upload speed: I'm following common advice for the fastest image format (32-bit BGRA, even though I don't need nearly that much precision) and fastest technique for updating the texture (glTexSubImage2D).

    I instantiate the texture object like this:

    Code :
    	glGenTextures(1, &originalTexture);
    	glBindTexture(GL_TEXTURE_RECTANGLE, originalTexture);
    	glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    	glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    	glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    	glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    	glTexImage2D(
    			GL_TEXTURE_RECTANGLE,
    			0,
    			GL_RGBA8,
    			atlas.Width,
    			atlas.Height,
    			0,
    			GL_BGRA,
    			GL_UNSIGNED_INT_8_8_8_8_REV,
    			nullptr);

    Then, I update it as needed at the start of a frame like this:

    Code :
    		glBindTexture(GL_TEXTURE_RECTANGLE, originalTexture);
    		glTexSubImage2D(
    			GL_TEXTURE_RECTANGLE,
    			0,
    			0,
    			0,
    			atlas.Width,
    			atlas.Height,
    			GL_BGRA,
    			GL_UNSIGNED_INT_8_8_8_8_REV,
    			atlas.getData());
    		glBindTexture(GL_TEXTURE_RECTANGLE, 0);

    I've tried on Windows with both Intel and Nvidia cards as well as on macOS with an AMD card, and I see the same behavior.

    What am I doing wrong?

    In case it matters, I use a version 3.3 Core Profile context, 24-bit color, 8-bit depth, 16-bit stencil, and double buffering.

  2. #2
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,969
    Looks OK, are you sure you are swapping correctly when you think you are and not triple buffering? Try reading the backbuffer right after the draw as a test. Check your subsequent bind as this should be immediately available after that subload.
    Try loading a test pattern instead of null data when you create it just to help debug. You needn't preserve image size between loads unless you are subloading, I expect your goal here is preallocation, YMMV, but no need for a full size image in your test/debug pattern if you replace that subload with a full load with internal format. I doubt you're saving much with a full image subload and I'd at least try replacing it with a load since you're not actually subloading. If you are subloading an atlas then I'd expect an atlas offset x and y and a larger width on the initialization.
    Last edited by dorbie; 05-28-2018 at 03:41 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •