Best way to clear only the viewport in DirectX 10?

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
unholysavagery
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 73
Joined: Tue Oct 28, 2008 4:27 am

Best way to clear only the viewport in DirectX 10?

Post by unholysavagery »

Well I'm trying to add a feature to my engine which allows multiple render targets to a window or texture, so you can do things like split screen coop games but I have a small problem I could fix in a crappy way but I'd like to know if anyone has a better idea. Well the problem is that when I clear the render target view it does not just clear the area in the viewport but also the entire render target view so I could just draw a quad to clear the screen but I think it may effect performance a bit. So does anyone know of a better way of clearing the area inside the viewport?
This is the internet, men are men, women are men and children are the FBI.
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Best way to clear only the viewport in DirectX 10?

Post by MarauderIIC »

Are you looking for a DirectX equivalent of http://sdl.beuc.net/sdl.wiki/SDL_UpdateRect then?
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
Trask
ES Beta Backer
ES Beta Backer
Posts: 738
Joined: Wed Oct 29, 2008 8:17 pm
Current Project: Building a 2D Engine
Favorite Gaming Platforms: Sega Genesis and Xbox 360
Programming Language of Choice: C/C++
Location: Pittsburgh, PA
Contact:

Re: Best way to clear only the viewport in DirectX 10?

Post by Trask »

Hey, I hope this helps as this is the only clear thing that I can find:

Use IDirect3DDevice9::Clear to clear the viewport. The method accepts one or more rectangles that define the areas on the surface being cleared. Setting the Count parameter to 1, and the pRects parameter to the address of a single rectangle that covers the entire viewport area will clear the entire viewport. Another way to clear the entire viewport is to set the pRects parameter to NULL and the Count parameter to 0.

This is coming from: http://msdn.microsoft.com/en-us/library ... S.85).aspx and it's using DirectX 9, but it will hopefully step you in the right direction.

http://msdn.microsoft.com/en-us/library ... S.85).aspx <- This is DirectX 10 specific, but I couldn't find what you're looking for on a cursory glance, it's quite possible that the syntax may be the same, but I'm sure you'd be able to dig it out of here quicker than me.
MarauderIIC wrote:You know those people that are like "CHECK IT OUT I just made Linux run on this piece of celery [or other random object]!!"? Yeah, that's Falco, but with ES.
Dear god, they actually ported ES to a piece of celery!
Martin Golding wrote: "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
User avatar
unholysavagery
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 73
Joined: Tue Oct 28, 2008 4:27 am

Re: Best way to clear only the viewport in DirectX 10?

Post by unholysavagery »

Well some random guy on the XNA forums said the only way to do it is to use a quad, so since I have nothing else to go on it's my only option.
This is the internet, men are men, women are men and children are the FBI.
User avatar
unholysavagery
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 73
Joined: Tue Oct 28, 2008 4:27 am

Re: Best way to clear only the viewport in DirectX 10?

Post by unholysavagery »

MarauderIIC wrote:Are you looking for a DirectX equivalent of http://sdl.beuc.net/sdl.wiki/SDL_UpdateRect then?
No thanks this is a 3D engine that is being built for many years from now so DirectX 10 is a viable option for me, though clearly microsoft has not smoothed out all the rough edges yet.
This is the internet, men are men, women are men and children are the FBI.
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Best way to clear only the viewport in DirectX 10?

Post by MarauderIIC »

I wasn't saying use SDL, I was asking if that did the same type of thing. Update a portion of the screen. If you're not drawing to it any more, then...
Trask's solution doesn't work?
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
unholysavagery
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 73
Joined: Tue Oct 28, 2008 4:27 am

Re: Best way to clear only the viewport in DirectX 10?

Post by unholysavagery »

MarauderIIC wrote:I wasn't saying use SDL, I was asking if that did the same type of thing. Update a portion of the screen. If you're not drawing to it any more, then...
Trask's solution doesn't work?
Yeah it's kinda like that, You create a render target which is only suppose to use one area of a window or texture and I also want to make it so when you define a render target that is out side of the viewable area of a window then it will add scroll bars. So you could use the engine not just for games but even applications. But I've found another problem that makes the rendering a quad not work as well because when I tell DirectX to render to a viewport it does not just render to the view port it also renders black to everything outside the viewport. So it clears all the other render targets which creates flickering.

Also Trask just linked me to the msdn "Programming Guide for Direct3D 10" and "Viewports and Clipping (Direct3D 9)" DirectX 10 is pretty much completely different from DirectX 9.
This is the internet, men are men, women are men and children are the FBI.
User avatar
Trask
ES Beta Backer
ES Beta Backer
Posts: 738
Joined: Wed Oct 29, 2008 8:17 pm
Current Project: Building a 2D Engine
Favorite Gaming Platforms: Sega Genesis and Xbox 360
Programming Language of Choice: C/C++
Location: Pittsburgh, PA
Contact:

Re: Best way to clear only the viewport in DirectX 10?

Post by Trask »

I figured that they probably were different, but I was hoping they would be similar enough as not all iterations of the DirectX deprecate all the previous functions what not...

If you find the solution, please post it so that others that may come and have the same issue can benefit from this.
MarauderIIC wrote:You know those people that are like "CHECK IT OUT I just made Linux run on this piece of celery [or other random object]!!"? Yeah, that's Falco, but with ES.
Dear god, they actually ported ES to a piece of celery!
Martin Golding wrote: "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
Post Reply