Hi,
I was writing a small test for modifications I made in some code to support glScissor calls in render batches and ran into an issue.
The test simply draws a rectangle twice with different textures (green or red) and glScissor calls.
If I write
| // frame start
rect2 r = { 0, 0, 100, 100 };
glScissor( a );
glDraw( r );
glScissor( b );
glDraw( r );
swap_buffers( );
|
The result is what I expect: 2 rectangles corresponding to the scissor setups.
If I write
| // frame start
rect2 r = { 0, 0, 100, 100 };
glDraw( r )
glScissor( b )
glDraw( r )
glScissor( a )
swap_buffers( );
|
I would expect a 100 x 100 rectangle and a second rectangle corresponding to the first scissor call on the first frame, than on subsequent frames the two rectangles similar to the first example.
Instead I get the first frame and second frame alternating. It's like OpenGL cached the frame buffers and doesn't see that the last glScissor call will affect the next frame rendering. If I resize the window then the rendering works as expected. I did some captures in RenderDoc and everything seems correct (events, mesh input/output, rasterizer scissor state).
Is there something I'm missing or not aware of ? I search a little bit in the
OpenGL 3.3 spec but didn't find anything useful (I don't know what to search for).
At some point I changed the code that creates the rectangle to be:
| static u32 frame = 0;
rect2 r = r2_min_size( ( r32 ) frame, 0, ( r32 ) width, ( r32 ) height );
frame++;
|
And it became even weirder: one of the rectangle seem to be subtracted, and the other doesn't resize unless I resize the window. Note that the application contains a Sleep( 1000 ); so you would need to wait 10 seconds before seeing a difference.
The only way I got the right result (with the rectangle moving, the code just above) was to have the scissor NOT cross frame boundaries AND disable the scissor test before swapping the buffers.
Here is the
compiled exe, source and build script. The program entry point is in quick/main.c and the test code is in the #if TEST_IMAGE.
Does anyone knows what could be happening ?