Skip to content
This repository was archived by the owner on Dec 14, 2021. It is now read-only.

set clip rect to full window size #7

Closed
wants to merge 1 commit into from

Conversation

jesselawson
Copy link

Fixes #6

@Tyyppi77
Copy link
Owner

I'm a little short on time these days, so I can't try this out, but I don't think we could discard whatever clip rects ImGui is feeding us, as it might actually be important clipping, for like a scroll-area or something? I might be mistaken too.

@jesselawson
Copy link
Author

jesselawson commented Oct 16, 2019

The ImGUISDL function SetClipRect is defined below:

void SetClipRect(const ClipRect& rect)
{
	Clip = rect;
	const SDL_Rect clip = { rect.X, rect.Y, rect.Width, rect.Height };
	SDL_RenderSetClipRect(Renderer, &clip);
}

Notice that its purpose is to pass a clip rect to SDL_RenderSetClipRect, which is defined is below:

int
SDL_RenderSetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect)
{
    CHECK_RENDERER_MAGIC(renderer, -1)

    if (rect) {
        renderer->clip_rect.x = (int)SDL_floor(rect->x * renderer->scale.x);
        renderer->clip_rect.y = (int)SDL_floor(rect->y * renderer->scale.y);
        renderer->clip_rect.w = (int)SDL_ceil(rect->w * renderer->scale.x);
        renderer->clip_rect.h = (int)SDL_ceil(rect->h * renderer->scale.y);
    } else {
        SDL_zero(renderer->clip_rect);
    }
    return renderer->UpdateClipRect(renderer);
}

UpdateClipRect is dispatched based on the underlying rendering API (e.g., OpenGL or D3D), and all it does is use the computed rectangle above to set the scissor test rectangle. The scissor test just means that anything rendered to the window that falls within that rectangle will be rendered, and anything outside of that rectangle will be discarded. I think this is why when you move a ImGui window without #7 you will only have that window's internal rect updated, and a trail of artifacts "behind" it. Telling SDL to scissor the entirety of the screen tells the rendering API to continue updating those pixels where the ImGui window used to be, even though there's no more ImGui pixels there (just the "background").

@Tyyppi77
Copy link
Owner

I know what clip recting does, and what you are suggesting here is essentially disabling clip recting totally (since a fullscreen cliprect means that everything rendered will pass the clip test). However, the ImGui rendering API provides us with a clip rect that it has most certainly deemed necessary, and hence discarding that doesn't seem wise to me.

@JayFoxRox
Copy link

JayFoxRox commented Nov 14, 2019

This should probably be rejected, if #6 (comment) is correct.

We should wait for SDL 2.0.11 and hope that SDL 2.0.9 / SDL 2.0.10 (those should be the only ones that are broken) don't propagate into any LTS releases.

@jesselawson
Copy link
Author

I'm inclined to agree with @JayFoxRox. We can wait until the new version of SDL, and ensure that the issue does not persist into a new version.

@Tyyppi77
Copy link
Owner

Great, I'll close this one!

@Tyyppi77 Tyyppi77 closed this Nov 14, 2019
@Sackzement
Copy link

Sackzement commented Jul 20, 2020

After creating the Renderer calling SDL_RenderSetClipRect with any SDL_Rect* but nullpr fixes the problem for me:

SDL_Renderer* ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
SDL_RenderSetClipRect(ren, &SDL_Rect());

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Windows 10: Window not being cleared correctly
5 participants