| Summary: | SDL_RenderSetClipRect doesn't work properly when use SDL_RenderSetLogicalSize | ||
|---|---|---|---|
| Product: | SDL | Reporter: | neo <neo333_email> |
| Component: | render | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | leonardo.guilherme, raincomplex, valentin.soudier, vii |
| Version: | 2.0.1 | Keywords: | target-2.0.4 |
| Hardware: | x86_64 | ||
| OS: | Windows 8 | ||
| Attachments: |
An example from code.
Uses viewport x and y to set cliprect x/y add viewport x/y to clipping rectangle Adds viewport x/y to cliprect in UpdateClipRect + D3D |
||
*** Bug 2336 has been marked as a duplicate of this bug. *** Created attachment 1674 [details]
Uses viewport x and y to set cliprect x/y
Hello. This bug happens because the viewport x/y is not being taken in consideration when setting the clipping rectangle (and render logical size is implemented as a combination of viewport and scale)
With the proposed patch, I've fixed this problem for the OpenGL[ES[2]] renderers but I have no idea if such problems occur in the DirectX renderer (couldn't be sure after superficially analyzing its code). Also I havent tested it in more odd combinations of scaling, viewport, target textures, etc.
As a workaround until this is fixed, one can get the viewport and add its x/y coordinates to the clipping rectangle:
SDL_Rect clip;
SDL_RenderGetViewport(renderer, &clip);
clip.x += 100, clip.y += 100, clip.w = 100, clip.w = 100;
SDL_RenderSetClipRect(renderer, &clip);
Created attachment 1882 [details]
add viewport x/y to clipping rectangle
Patch fixes the issue.
Workaround for unpatched SDL:
SDL_Rect c = {...}; // clipping rectangle
SDL_Rect vp;
SDL_RenderGetViewport(renderer, &vp);
c.x += vp.x;
c.y -= vp.y;
SDL_RenderSetClipRect(renderer, &c);
Created attachment 2010 [details]
Adds viewport x/y to cliprect in UpdateClipRect + D3D
Hello. I was affected by this bug and found Leonardo's patch to work better than raincomplex's. I guess it's better to add the viewport coordinates when the driver updates the scissor rect than to do it beforehand.
Attached patch is the same as Leonardo's but with fix for D3D added.
*** Bug 2336 has been marked as a duplicate of this bug. *** Fixed, thanks! https://hg.libsdl.org/SDL/rev/1d13a878b066 |
Created attachment 1473 [details] An example from code. -------------Info machine:--------- OS: Win8 (64bit) SDL Version: 2.0.1 HW Video: AMD Radeon HD 7600M series ------------------------------------ --------------Code example:----------------------------- //Now i'm window 1280x800 [for example] SDL_Window* win = SDL_CreateWindow("title",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,1280,800,SDL_WINDOW_RESIZABLE); ... //[create renderer with SDL_RENDERER_ACCELERATED] //My application is designed for 800x600 SDL_RenderSetLogicalSize(renderer,800,600); SDL_Texture* texture = ... //load all //main loop while(true){ SDL_RenderClear(renderer); SDL_RenderSetClipRect(renderer, Rect(0,0,800,600)); //Rect = easy SDL_Rect wrapper class. SDL_RenderCopy(renderer,texture,NULL,NULL); SDL_RenderSetClipRect(renderer,NULL); SDL_RenderPresent(renderer); } ------------------------------------------------------- As you can see from the attached 'SDL_RenderSetClipRect' does not work well because the area of the clip does not coincide with the area set on 'SDL_RenderSetLogicalSize'.