Thanks! That’s pretty much exactly my line of reasoning for wanting a
single function, expressed a lot better than I was able to.
Den Wed, 1 Jul 2009 22:10:34 +0200
skrev florent boudet :
I made a separate function to make it more clear to the API user.
SDL_TextureID and SDL_WindowID appear to be of different type to the
user, although both are uint32 and come from the same pool.
Both approach have their advantages (mine is more clear to the user
imo, yours adds less bloat to the API).
I disagree. With Mason Wheeler’s approach, SelectRenderer always
sets the target for your renders, whatever that may be. When you
look at it that way, ie what you actually want to accomplish by using
the function (“i want to render things to there!”), it’s easy to use
and easy to understand. SelectRenderer can be described simply as “set
target for rendering”. (The user has to know that both windows and
textures can be targets, but they’d have to know that anyway to want to
render to textures in the first place, or to go looking for a
SetTargetTexture function for that matter.)
With two functions, the SelectRenderer description changes to something
like “set target window for rendering, unless rendering to a texture”.
SetTargetTexture could then be “set target texture for rendering, or 0
to revert target to the previously selected window”. Not a huge change,
but it’s more to keep in mind for new users, and leads to questions
like this:
SDL_SetTargetTexture(texture);
SDL_SelectRenderer(window);
Assuming the texture is nonzero, if these two functions are called in
this order, what is the result? Does SelectRenderer implicitly
call SetTargetTexture(0), or does it merely set the window to render to
once SetTargetTexture(0) is explicitly called some time in the future?
This is not clear.
SDL_SelectRenderer(texture);
SDL_SelectRenderer(window);
Probably no need to look things up in the documentation here. It’s just
changing the one state.
Having just one function for both windows and texture targets also makes
things easier if you want to change code that currently renders to a
window to render to a texture in stead (let’s say the shiny new version
of your engine wants to support fancy post-processing). No need to
change any calls if they’re the same in either case!
- GerryFrom: trick@icculus.org (Gerry Jo Jellestad)
Subject: Re: [SDL] [PATCH] SDL 1.3: Drawing from one texture to another